我正在使用EclipseLink 2.6.3(也尝试使用2.6.2),我面临着一个非常奇怪的情况:数据库(Oracle 12c)抱怨以下消息:
ORA-02291:违反了完整性约束(LOG_SUB_LO_ID_FK) - 未找到父密钥
但是,在查看日志时,他们似乎建议引用的父键应该在那里,它们显示以下内容:
2016-12-01 09:08:26,601 [grizzly-http-server-2] DEBUG org.eclipse.persistence.sql - INSERT INTO LOGS (ID, CREATION_DATE) VALUES (?, ?)
bind => [4368, 2016-12-01 09:08:26.601]
2016-12-01 09:08:26,604 [grizzly-http-server-2] DEBUG org.eclipse.persistence.sql - INSERT INTO LOG_PARAM (ID, CREATION_DATE, LO_ID) VALUES (?, ?, ?)
bind => [4369, 2016-12-01 09:08:26.601, 4368]
2016-12-01 09:08:26,607 [grizzly-http-server-2] DEBUG org.eclipse.persistence.sql - INSERT INTO LOG_SUB (ID, CREATION_DATE, LO_ID) VALUES (?, ?, ?)
bind => [4370, 2016-12-01 09:08:26.601, 4368]
2016-12-01 09:08:26,624 [grizzly-http-server-2] DEBUG org.eclipse.persistence.sql - SELECT 1 FROM DUAL
2016-12-01 09:08:26,645 [grizzly-http-server-2] WARN org.eclipse.persistence -
org.eclipse.persistence.exceptions.DatabaseException:
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint (LOG_SUB_LO_ID_FK) violated - parent key not found
Error Code: 2291
Call: INSERT INTO LOG_SUB (ID, CREATION_DATE, LO_ID) VALUES (?, ?, ?)
bind => [4370, 2016-12-01 09:08:26.601, 4368]
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:902)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:964)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:633)
at org.eclipse.persistence.internal.databaseaccess.ParameterizedSQLBatchWritingMechanism.executeBatch(ParameterizedSQLBatchWritingMechanism.java:149)
at org.eclipse.persistence.internal.databaseaccess.ParameterizedSQLBatchWritingMechanism.executeBatchedStatements(ParameterizedSQLBatchWritingMechanism.java:134)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.writesCompleted(DatabaseAccessor.java:1845)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.commitTransaction(DatabaseAccessor.java:428)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicCommitTransaction(AbstractSession.java:814)
at org.eclipse.persistence.sessions.server.ClientSession.basicCommitTransaction(ClientSession.java:182)
at org.eclipse.persistence.internal.sessions.AbstractSession.commitTransaction(AbstractSession.java:1018)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitTransaction(UnitOfWorkImpl.java:1600)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitTransaction(RepeatableWriteUnitOfWork.java:650)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitTransactionAfterWriteChanges(UnitOfWorkImpl.java:1615)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:285)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:1169)
...
Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint (LOG_SUB_LO_ID_FK) violated - parent key not found
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:587)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:225)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:53)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:943)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1150)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4798)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:4875)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1361)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:892)
表格如下:
映射到JPA对象相对简单:
Log
类(与LOGS表匹配)与LogSub和LogParam的2 @OneToMany
个关系,标记为级联ALL LogSub
(对于LOG_SUB表)和LogParam
(对于LOG_PARAM表)都与@ManyToOne
的关系Log
被标记为不可为空且可选= false 我创建了我的Log
对象并添加了1个LogSub和1个LogParam(每个关系一个),然后保留我的Log对象。
当我的交易提交时,我随机收到上述错误。
有关信息:我正在使用EclipseLink与Spring-Jpa和Spring-Data以及启用JDBC批处理写入。
为简单起见,我删除了一些数据
如有需要,请随时提出更多详情。