mysql - 无法添加或更新子行: a foreign key constraint fails - liferay

标签 mysql liferay

我收到以下错误

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/

相关文章:

java - 如何反向移植 6.1.1 jsf portlet 以使其在 6.1.0 liferay 门户上运行?

jakarta-ee - TOMCAT 在子目录中有 webapps

java - Liferay 控制台 Groovy 脚本缺少方法错误

java - Grails - 创建数据库 View

MySQL - 如何合并来自两个表的数据,使用一个字段的值作为过滤器来计算另一个字段中的值?

mysql - 没有变量的命名数组

PHP Lua注册系统

javascript - Portlet 中的YUI 版本冲突问题

Liferay - 使用第三方库不起作用

php - Laravel: `loadMissing` 函数的目的是什么?