From 5d8a45ca0c07846aebcef42dae103a381d258e76 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 7 May 2014 16:14:51 -0700 Subject: [PATCH] HHH-9171 : Orphan removal broken for new element added by merge that is removed by later merge (test case) --- .../org/hibernate/test/orphan/OrphanTest.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/test/orphan/OrphanTest.java b/hibernate-core/src/test/java/org/hibernate/test/orphan/OrphanTest.java index 9a0314f12f..753d5615db 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/orphan/OrphanTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/orphan/OrphanTest.java @@ -30,6 +30,7 @@ import org.hibernate.LockMode; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.internal.util.SerializationHelper; +import org.hibernate.testing.FailureExpected; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.junit.Assert.assertNotNull; @@ -328,5 +329,69 @@ public class OrphanTest extends BaseCoreFunctionalTestCase { session.close(); } + @Test + @SuppressWarnings( {"unchecked"}) + public void testOrphanDeleteOnMergeRemoveElementMerge() { + Session session = openSession(); + Transaction t = session.beginTransaction(); + Product prod = new Product(); + prod.setName( "Widget" ); + Part part = new Part(); + part.setName("Widge"); + part.setDescription("part if a Widget"); + prod.getParts().add(part); + session.persist(prod); + t.commit(); + session.close(); + + session = openSession(); + t = session.beginTransaction(); + session.merge(prod); + prod.getParts().remove( part ); + session.merge( prod ); + t.commit(); + session.close(); + + session = openSession(); + t = session.beginTransaction(); + assertNull( session.get( Part.class, "Widge" ) ); + session.delete( session.get(Product.class, "Widget") ); + t.commit(); + session.close(); + } + + @Test + @SuppressWarnings( {"unchecked"}) + @FailureExpected(jiraKey = "HHH-9171") + public void testOrphanDeleteOnAddElementMergeRemoveElementMerge() { + Session session = openSession(); + Transaction t = session.beginTransaction(); + Product prod = new Product(); + prod.setName( "Widget" ); + session.persist(prod); + t.commit(); + session.close(); + + Part part = new Part(); + part.setName("Widge"); + part.setDescription("part if a Widget"); + prod.getParts().add(part); + + session = openSession(); + t = session.beginTransaction(); + session.merge(prod); + prod.getParts().remove(part); + session.merge( prod ); + t.commit(); + session.close(); + + session = openSession(); + t = session.beginTransaction(); + assertNull( session.get( Part.class, "Widge" ) ); + session.delete( session.get(Product.class, "Widget") ); + t.commit(); + session.close(); + } + }