From 65eebbb96b2a5557867994c27b382e9da6f22b12 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 20 Mar 2019 17:26:32 -0700 Subject: [PATCH] HHH-13241 : Added test case with a lazy null many-to-one association --- .../lazy/BidirectionalLazyTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/BidirectionalLazyTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/BidirectionalLazyTest.java index 867d965be5..ed6e755a17 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/BidirectionalLazyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/BidirectionalLazyTest.java @@ -173,6 +173,40 @@ public class BidirectionalLazyTest extends BaseCoreFunctionalTestCase { ); } + @Test + public void testRemoveEntityWithNullLazyManyToOne() { + + doInHibernate( + this::sessionFactory, session -> { + Employer employer = new Employer( "RedHat" ); + session.persist( employer ); + Employee employee = new Employee( "Jack" ); + session.persist( employee ); + } + ); + + doInHibernate( + this::sessionFactory, session -> { + Employee employee = session.get( Employee.class, "Jack" ); + + // Get and delete an Employer that is not associated with employee + Employer employer = session.get( Employer.class, "RedHat" ); + session.remove( employer ); + + // employee.employer is uninitialized. Since the column for employee.employer + // is a foreign key, and there is an Employer that has already been removed, + // employee.employer will need to be iniitialized to determine if + // employee.employee is nullifiable. + assertFalse( Hibernate.isPropertyInitialized( employee, "employer" ) ); + session.remove( employee ); + assertTrue( Hibernate.isPropertyInitialized( employee, "employer" ) ); + } + ); + + + + } + private void checkEntityEntryState( final Session session, final Employee employee,