we upgraded our maven dependencies and after the migration from hibernate orm 5.3.10 to 5.4.10 our unidirectional relation does not work any more. Here are the entities:
As you can see we have only the relation from ParentEntity to ChildEntity with @OneToOne annotation.
When I create the parent entity and the child entity everything is ok so far. When I delete the parent entity I expect that the child will be deleted first and the parent afterwards. In 5.3.10 I have this order but in 5.4.10 the order is the other way (the parent will be deleted first and the child afterwards).
The sql log in 5.3.10 is the following:
The sql log in 5.4.10 is the following:
As you can see the delete order has changed.
As far as I have seen it has something to do with the following ticket https://hibernate.atlassian.net/browse/HHH-12436 and the changes in the hibernate class org.hibernate.cfg.OneToOneSecondPass#doSecondPass.
There is the following code:
hibernate will set the foreignKeyDirection to FROM_PARENT in case mappedBy is not set (which is the case see above).
In hibernate 5.3.10 the following if statement returned true and in 5.4.10 this returns false:
I assume the above if statement is not the bug but in this line the bug will have it’s impact.
Here is a simple example:
To reproduce my issue just change the hibernate version in pom.xml.
To me it looks like a bug cause the behavior is different. In case I am wrong could you tell me how to create a unidirectional relation correctly?