Orphan removal does not work for OneToOne relations

Description

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.

Environment

Tested with PostgreSQL 9.3

Activity

Show:
Chris Cranford
March 23, 2017, 9:12 PM

, 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.

Chris Cranford
March 23, 2017, 9:35 PM
Edited

, 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.

Gail Badner
April 14, 2017, 4:13 AM

Fixed in master.

Jaanus Hansen
April 9, 2018, 10:14 PM

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:

https://github.com/hibernate/hibernate-orm/pull/2233

Gail Badner
May 18, 2018, 11:52 PM

, 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.

Assignee

Chris Cranford

Reporter

Arkadiusz Firus

Fix versions

backPortable

Backport?

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure