我收到以下错误
Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at com.liferay.portal.dao.orm.hibernate.SessionImpl.flush(SessionImpl.java:144)
... 192 more
Caused by: java.sql.BatchUpdateException: Cannot add or update a child row: a foreign key constraint fails (`audit_compliance`.`audit_compliance_auditdetailes`, CONSTRAINT `auditComplianceCompanyId` FOREIGN KEY (`auditComplianceCompanyId`) REFERENCES `audit_compliance_auditcompliancecompany` (`audit)
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2054)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1135)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
我使用的是liferay 6.2。它在服务构建器中没有映射键,因此我在数据库表中手动给出了引用。 引用是正确的,我不明白它给出错误的原因。
ALTER TABLE `audit_compliance`.`audit_compliance_auditdetailes`
DROP FOREIGN KEY `documentCollectionIds`;
ALTER TABLE `audit_compliance`.`audit_compliance_auditdetailes`
ADD CONSTRAINT `documentCollectionIds`
FOREIGN KEY (`documentCollectionIds`)
REFERENCES `audit_compliance`.`audit_compliance_documentcollection` (`name`);
最佳答案
由于 ServiceBuilder 不包含外键引用,因此它可能会使用错误的顺序将数据插入表中:现在您强制执行外键关系,但 ServiceBuilder 仍然不知道这一点。
决定是使用 ServiceBuilder 的持久性(那么您可能不想使用外键)还是自行推出。您仍然可以将 ServiceBuilder 用于服务层,并在后台使用您自己的持久性。
关于mysql - 无法添加或更新子行: a foreign key constraint fails - liferay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44451247/