Skip to content

Commit

Permalink
HHH-9171 : Orphan removal does not happen for new entity element
Browse files Browse the repository at this point in the history
  • Loading branch information
gbadner committed May 27, 2014
1 parent d26d396 commit 4362063
Showing 1 changed file with 8 additions and 2 deletions.
Expand Up @@ -31,6 +31,7 @@
import org.hibernate.Transaction;
import org.hibernate.internal.util.SerializationHelper;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;

import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -362,7 +363,7 @@ public void testOrphanDeleteOnMergeRemoveElementMerge() {

@Test
@SuppressWarnings( {"unchecked"})
@FailureExpected(jiraKey = "HHH-9171")
@TestForIssue(jiraKey = "HHH-9171")
public void testOrphanDeleteOnAddElementMergeRemoveElementMerge() {
Session session = openSession();
Transaction t = session.beginTransaction();
Expand All @@ -380,14 +381,19 @@ public void testOrphanDeleteOnAddElementMergeRemoveElementMerge() {
session = openSession();
t = session.beginTransaction();
session.merge(prod);
// In Section 2.9, Entity Relationships, the JPA 2.1 spec says:
// "If the entity being orphaned is a detached, new, or removed entity,
// the semantics of orphanRemoval do not apply."
// In other words, since part is a new entity, it will not be deleted when removed
// from prod.parts, even though cascade for the association includes "delete-orphan".
prod.getParts().remove(part);
session.merge( prod );
t.commit();
session.close();

session = openSession();
t = session.beginTransaction();
assertNull( session.get( Part.class, "Widge" ) );
assertNotNull( session.get( Part.class, "Widge" ) );
session.delete( session.get(Product.class, "Widget") );
t.commit();
session.close();
Expand Down

0 comments on commit 4362063

Please sign in to comment.