Orphan removal in @OneToMany does not work properly (JPA 2.0)

Description

Consider following entities (getters, setters, equals and hashCode are omitted for brevity):

According to the specification of JPA 2.0 (section 11.1.36), removing a child entity from the parent's children collection should lead to it being removed from the database. However, following code leaves an orphaned child entity stored in the database:

Removing a parent entity however works fine (no orphans remain in the database).

I have attached a JUnit test case illustrating the behavior. I ran the test against another persistence provider, where the orphan was removed as expected.

I have also included the Hibernate-equivalent of the test (using Hibernate's native API instead of JPA). This code also cleans up the orphan as expected. Thus the bug seems to be related to the JPA implementation (EntityManager etc).

Attachments

1

Activity

Show:

Christian Beikov January 9, 2025 at 1:02 PM

This was probably fixed through already.

Former user December 5, 2016 at 9:40 PM

Is this a duplicate of HHH-10123?

Renato Justo November 8, 2016 at 4:21 PM
Edited

Hi, I have same problem, I did the tests and also does not work.

Torsten Krah November 8, 2016 at 3:43 PM
Edited

Hi - i can't edit the "Affects version" (maybe only the author can) - i can confirm its still not working (5.2.2.Final), see:

https://github.com/tkrah/hibernate-test-case-templates/commit/ad2f9e30deffdfaa0cad2403b490fedae630d784

Steve Ebersole October 28, 2015 at 3:25 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Out of Date

Assignee

Reporter

Components

Affects versions

Priority

Created October 5, 2011 at 11:07 AM
Updated January 9, 2025 at 1:02 PM
Resolved January 9, 2025 at 1:02 PM
Loading...