From 0eb187fae49f3e24a1d6ebafa3913f8112b0a083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 7 Jun 2021 10:40:38 +0200 Subject: [PATCH] HHH-14659 Test join fetch correctly in HHH3949Test --- .../test/bytecode/enhancement/join/HHH3949Test.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/join/HHH3949Test.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/join/HHH3949Test.java index e39604755e..6ab4bc36a2 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/join/HHH3949Test.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/join/HHH3949Test.java @@ -23,6 +23,7 @@ import javax.persistence.Table; import java.util.List; import static org.hibernate.Hibernate.isInitialized; +import static org.hibernate.Hibernate.isPropertyInitialized; import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -131,6 +132,11 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase { for ( Person person : persons ) { assertTrue( isInitialized( person ) ); if ( shouldHaveVehicle( person ) ) { + // We used a "join fetch", so the vehicle must be initialized + // before we even call the getter + // (which could trigger lazy initialization if the join fetch didn't work). + assertTrue( isPropertyInitialized( person, "vehicle" ) ); + assertNotNull( person.getVehicle() ); assertTrue( isInitialized( person.getVehicle() ) ); assertNotNull( person.getVehicle().getDriver() ); @@ -146,6 +152,11 @@ public class HHH3949Test extends BaseCoreFunctionalTestCase { } for ( Vehicle vehicle : vehicles ) { if ( shouldHaveDriver( vehicle ) ) { + // We used a "join fetch", so the drover must be initialized + // before we even call the getter + // (which could trigger lazy initialization if the join fetch didn't work). + assertTrue( isPropertyInitialized( vehicle, "driver" ) ); + assertNotNull( vehicle.getDriver() ); assertNotNull( vehicle.getDriver().getVehicle() ); }