diff --git a/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/DeleteOneToOneOrphansTest.java b/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/DeleteOneToOneOrphansTest.java index 10af9aad50..a2e7428b83 100644 --- a/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/DeleteOneToOneOrphansTest.java +++ b/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/DeleteOneToOneOrphansTest.java @@ -89,4 +89,44 @@ public class DeleteOneToOneOrphansTest extends FunctionalTestCase { cleanupData(); } + + public void testOrphanedWhileDetachedFailureExpected() { + createData(); + + Session session = openSession(); + session.beginTransaction(); + List results = session.createQuery( "from EmployeeInfo" ).list(); + assertEquals( 1, results.size() ); + results = session.createQuery( "from Employee" ).list(); + assertEquals( 1, results.size() ); + Employee emp = ( Employee ) results.get( 0 ); + assertNotNull( emp.getInfo() ); + + //only fails if the object is detached + session.getTransaction().commit(); + session.close(); + session = openSession(); + session.beginTransaction(); + + emp.setInfo( null ); + + //save using the new session (this used to work prior to 3.5.x) + session.saveOrUpdate(emp); + + session.getTransaction().commit(); + session.close(); + + session = openSession(); + session.beginTransaction(); + emp = ( Employee ) session.get( Employee.class, emp.getId() ); + assertNull( emp.getInfo() ); + results = session.createQuery( "from EmployeeInfo" ).list(); + assertEquals( 0, results.size() ); + results = session.createQuery( "from Employee" ).list(); + assertEquals( 1, results.size() ); + session.getTransaction().commit(); + session.close(); + + cleanupData(); + } } \ No newline at end of file