Milad (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiODdmNTI5M2M3...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16244?atlOrigin=eyJpIjoiODdmNT...
) HHH-16244 (
https://hibernate.atlassian.net/browse/HHH-16244?atlOrigin=eyJpIjoiODdmNT...
) Cannot delete entities with one-to-one and bidirectional one-to-many relationship (
https://hibernate.atlassian.net/browse/HHH-16244?atlOrigin=eyJpIjoiODdmNT...
)
Issue Type: Bug Affects Versions: 6.1.7 Assignee: Unassigned Attachments: reproduction.zip
Components: hibernate-orm-modules Created: 02/Mar/2023 05:43 AM Environment: Hibernate
6.1.7.Final. Unit test case provided with template
https://github.com/hibernate/hibernate-test-case-templates/tree/main/orm/... (
https://github.com/hibernate/hibernate-test-case-templates/tree/main/orm/... )
Priority: Blocker Reporter: Milad (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
I have EntityA and EntityB. There exist the following relationships:
* One-to-one relationship from EntityA to EntityB.
* Bidirectional one-to-many relationship from EntityA to EntityB.
To remove both entities, I first clear all references, then call session.remove() on both
entities. This results in this exception:
jakarta.persistence.PersistenceException: Converting
`org.hibernate.exception.ConstraintViolationException` to JPA `PersistenceException` :
could not execute statement
at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:165)
at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:175)
at
org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:182)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1429)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:477)
at
org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2234)
at
org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:1930)
at
org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:439)
at
org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:183)
at
org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:281)
at
org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101)
at org.hibernate.bugs.ORMUnitTestCase.hhh123Test(ORMUnitTestCase.java:110)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at
org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at
org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
at
org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute
statement
at
org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:60)
at
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:56)
at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95)
at
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:200)
at
org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:39)
at
org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:3763)
at
org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:4116)
at
org.hibernate.action.internal.EntityDeleteAction.execute(EntityDeleteAction.java:126)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:612)
at
org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:483)
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:480)
at
org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:329)
at
org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at
org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:107)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1425)
... 23 more
Caused by: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: Referentielle
Integritõt verletzt: "FK8QCPYR2C217Q3RPPCGGGR7ST3: PUBLIC.ENTITYA FOREIGN
KEY(SELECTEDENTITYBID) REFERENCES PUBLIC.ENTITYB(ENTITYBID) (2)"
Referential integrity constraint violation: "FK8QCPYR2C217Q3RPPCGGGR7ST3:
PUBLIC.ENTITYA FOREIGN KEY(SELECTEDENTITYBID) REFERENCES PUBLIC.ENTITYB(ENTITYBID)
(2)"; SQL statement:
delete from EntityB where EntityBId=? [23503-214]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:508)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:477)
at org.h2.message.DbException.get(DbException.java:223)
at org.h2.message.DbException.get(DbException.java:199)
at
org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:365)
at
org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:382)
at
org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:256)
at org.h2.table.Table.fireConstraints(Table.java:1172)
at org.h2.table.Table.fireAfterRow(Table.java:1190)
at org.h2.command.dml.Delete.update(Delete.java:92)
at org.h2.command.dml.DataChangeStatement.update(DataChangeStatement.java:74)
at org.h2.command.CommandContainer.update(CommandContainer.java:169)
at org.h2.command.Command.executeUpdate(Command.java:252)
at
org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:209)
at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:169)
at
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:197)
... 35 more
See reproduction based on template
https://github.com/hibernate/hibernate-test-case-templates/tree/main/orm/... (
https://github.com/hibernate/hibernate-test-case-templates/tree/main/orm/... )
:
(
https://hibernate.atlassian.net/browse/HHH-16244#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16244#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100217- sha1:65be9f2 )