java 休眠插入问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6594069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:32:09  来源:igfitidea点击:

Hibernate insertion issue

javahibernatejpa-2.0

提问by Cris

I have two entities:PS_PUBLICATION and PS_PUBLICATION_PROPERTIES

我有两个实体:PS_PUBLICATION 和 PS_PUBLICATION_PROPERTIES

PS_PUBLICATION has a list of PS_PUBLICATION_PROPERTIES

PS_PUBLICATION 有一个 PS_PUBLICATION_PROPERTIES 列表

In the logs the inserts look fine but at the end i got an error

在日志中,插入看起来不错,但最后我得到了一个错误

insert into PS_PUBLICATION (CREATION_DATE, message, FK_SUBJECTAREA_ID, status, subject, UPDATE_DATE, id) values (?, ?, ?, ?, ?, ?, ?) 

binding '2011-07-06 10:36:43' to parameter: 1 

binding 'dc8ca7f0-9d8d-11e0-89b1-00212834363a' to parameter: 3 

binding 'PUBLISHED' to parameter: 4 

binding 'publication 2' to parameter: 5 

binding '2011-07-06 10:36:43' to parameter: 6 

binding '13d6df10-a7ab-11e0-ac48-00212834ce10' to parameter: 7 

insert into PS_PUBLICATION_PROPERTIES (PROP_VALUE, PROP_KEY, FK_PUBLICATION_ID) values (?, ?, ?) 

binding 'close' to parameter: 1 

binding 'CALL-CATEGORY-OPEN' to parameter: 2 

binding '13d6df10-a7ab-11e0-ac48-00212834ce10' to parameter: 3 

06 Jul 2011 10:36:43,680  WARN org.hibernate.util.JDBCExceptionReporter:100 - SQL Error: 2291, SQLState: 23000
06 Jul 2011 10:36:43,681 ERROR org.hibernate.util.JDBCExceptionReporter:101 - ORA-02291: integrity constraint (EPF7_NOTIF.SYS_C0018903) violated - parent key not found

WARN org.hibernate.util.JDBCExceptionReporter:100
    - SQL Error: 2291, SQLState: 23000 06 Jul 2011 10:36:43,690 ERROR org.hibernate.event.def.AbstractFlushingEventListener:324
    - Could not synchronize database state with session org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update   
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)

In the inserts everythign look fine !

在插入物的每一个看起来都很好!

Any idea what might cause this ?

知道是什么原因造成的吗?

Thank you !

谢谢 !

回答by Andreas Dolk

org.hibernate.exception.ConstraintViolationException:

org.hibernate.exception.ConstraintViolationException

Implementation of JDBCException indicating that the requested DML operation resulted in a violation of a defined integrity constraint.

JDBCException 的实现指示请求的 DML 操作导致违反定义的完整性约束。

Double check if the data you want to insert does not violate database constraints. It looks like the database isn't happy with the values.

仔细检查您要插入的数据是否不违反数据库约束。看起来数据库对这些值不满意。

(If you catch that exception, call ex.getConstraintName(), that should give more details.)

(如果您捕获该异常,请调用ex.getConstraintName(),它应该提供更多详细信息。)

Didn't notice, the the constraint name was in the question ;) You'll find that constraint's definition in the database. Ask your oracle instance and it will tell you, which table and thus which insert causes trouble.

没有注意到,约束名称在问题中;) 您会在数据库中找到该约束的定义。询问您的 oracle 实例,它会告诉您哪个表以及哪个插入会导致问题。



Error:ORA-02291: integrity constraint violated - parent key not found

Cause:You tried to reference a table using a unique or primary key, but the columns that you listed did not match the primary key, or a primary key does not exist for this table.

错误:ORA-02291:违反完整性约束 - 未找到父键

原因:您尝试使用唯一键或主键引用表,但您列出的列与主键不匹配,或者该表不存在主键。

You provide two UUIDs as foreign keys - one of them is not a primary key in some other table. Or at least - not recognized as a primary key by oracle.

您提供两个 UUID 作为外键 - 其中一个不是其他表中的主键。或者至少 - 不被 oracle 识别为主键。

This link may help.

此链接可能会有所帮助