According to JPA 2.1 specification (page 476) if an entity is removed from the one to one relation (by setting the reference to null) and the relation is marked with orphan removal, the referenced entity should be deleted from the database.
When I created one sided (no reverse reference) one to one relationship between two entities and set the orphan removal attribute to true, the referenced object is still in database after setting reference to null.
If you have any questions/suggestions feel free to ask.
Tested with PostgreSQL 9.3
, I didn't see that using EAGER presented the problem the issue describes. Only when fetch-type was set to LAZY could I reproduce the issue.
The fix here simply seemed to be adding an additional path to determining the entityName needed for the cascade code rather than the short-circuit approach applied for HHH-7829. I'm adding a few more tests to verify the solution has no side affects, but thus far its promising.
, it seems when bootstrapped using native Hibernate SessionFactory, EAGER works. When bootstrapped as JPA's EntityManagerFactory, EAGER fails. I didn't expect there to be a difference in 5.2, but I'll track that down too.
Fixed in master.
I think that I noticed one more case, where orphanRemoval=true is not removing orphans.
It is not working when the @OneToOne(orphanRemoval=true) property is in @Embeddable object.
Here is a failing test:
, if this is still an issue, please check to see if there is already an issue open with your use case; if not, please open a new issue with your pull request.