Referential Integrity Constraint Violation - Unidirectional OneToOne with Cascade.ALL, optional false and @PrimaryKeyColumnJoin
Description
Beginning from 5.2.14 our use case is not working anymore because of the change in HHH-9460. Our code looks like in the following:
Our use case is to share ID of parent without using Bidirectional association and while persisting parent, the child should be persisted with the ID of parent.
Before version 5.2.14, order of the relevant insert statements was:
Beginning from version 5.2.14, the order is:
This happens because parent has a foreign key constraint onto ID of child. If the parent will be persisted as first, child and ID of it does not exist, which causes ConstraintViolationException on flush.
Here is the Exception:
Problem in code is in class OneToOneSecondPass.java
Beginning from version 5.2.14 value.setForeignKeyType will be set to ForeignKeyDirection.TO_PARENT in our code. It was and should be set to ForeignKeyDirection.FROM_PARENT before version 5.2.14.
I tested this with the code above on 5.2.13.Final and there is no problem.
Hi sorry for delay I was finally able to write tests. Uploaded as attachment.
Unfortunately I dont have access to source code anymore. I tried to demonstrate it again as much as I remember. There is only one test case and switching the version from 5.2.13.Final to 5.2.14.Final causes an exception.
And 5.4.1.Final was successful with the test above. so no issues anymore. Thanks.
Veli Döngelci May 6, 2019 at 3:34 PM
Hi, I need to check it. I will drop a comment here afterwards.
Former user February 5, 2019 at 12:16 AM
, are you still running into this issue with 5.4.1?
Beginning from 5.2.14 our use case is not working anymore because of the change in HHH-9460. Our code looks like in the following:
Our use case is to share ID of parent without using Bidirectional association and while persisting parent, the child should be persisted with the ID of parent.
Before version 5.2.14, order of the relevant insert statements was:
Beginning from version 5.2.14, the order is:
This happens because parent has a foreign key constraint onto ID of child. If the parent will be persisted as first, child and ID of it does not exist, which causes ConstraintViolationException on flush.
Here is the Exception:
Problem in code is in class OneToOneSecondPass.java
Beginning from version 5.2.14 value.setForeignKeyType will be set to ForeignKeyDirection.TO_PARENT in our code. It was and should be set to ForeignKeyDirection.FROM_PARENT before version 5.2.14.
I tested this with the code above on 5.2.13.Final and there is no problem.