HHH-13241 : Added test case with a lazy null many-to-one association

This commit is contained in:
Gail Badner 2019-03-20 17:26:32 -07:00 committed by gbadner
parent 926e1da2d5
commit 65eebbb96b
1 changed files with 34 additions and 0 deletions

View File

@ -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( private void checkEntityEntryState(
final Session session, final Session session,
final Employee employee, final Employee employee,