From 1d965227c44b20597fc19d6ca6aa690753bf7324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Wed, 29 Jul 2020 11:38:05 +0200 Subject: [PATCH] HHH-14124 Test that the FETCH entitygraph semantic overrides EAGER associations to LAZY --- .../test/graphs/LoadAndFetchGraphTest.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/graphs/LoadAndFetchGraphTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/graphs/LoadAndFetchGraphTest.java index b078142afd..121e1d7beb 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/graphs/LoadAndFetchGraphTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/graphs/LoadAndFetchGraphTest.java @@ -186,7 +186,10 @@ public class LoadAndFetchGraphTest extends BaseEntityManagerFunctionalTestCase { assertFalse( Hibernate.isInitialized( cEntity.getC() ) ); assertFalse( Hibernate.isInitialized( cEntity.getdList() ) ); - assertEquals( 1L, statistics.getPrepareStatementCount() ); + assertTrue( Hibernate.isInitialized( cEntity.getEagerC() ) ); + + // 1 + 1 for the eager C + assertEquals( 2L, statistics.getPrepareStatementCount() ); } ); } @@ -217,7 +220,12 @@ public class LoadAndFetchGraphTest extends BaseEntityManagerFunctionalTestCase { assertTrue( Hibernate.isInitialized( dEntity.getE() ) ); } ); - assertEquals( 1L, statistics.getPrepareStatementCount() ); + // With LOAD semantic, attributes that are not mentioned in the graph are LAZY or EAGER, + // depending on the mapping. + assertTrue( Hibernate.isInitialized( cEntity.getEagerC() ) ); + + // 1 + 1 for the eager C + assertEquals( 2L, statistics.getPrepareStatementCount() ); } ); } @@ -247,6 +255,10 @@ public class LoadAndFetchGraphTest extends BaseEntityManagerFunctionalTestCase { assertTrue( Hibernate.isInitialized( dEntity.getE() ) ); } ); + // With FETCH semantic, attributes that are not mentioned in the graph are LAZY, + // even if they were EAGER in the mapping. + assertFalse( Hibernate.isInitialized( cEntity.getEagerC() ) ); + assertEquals( 1L, statistics.getPrepareStatementCount() ); } ); } @@ -366,6 +378,9 @@ public class LoadAndFetchGraphTest extends BaseEntityManagerFunctionalTestCase { @ManyToOne(fetch = FetchType.LAZY) private CEntity c; + @OneToOne(fetch = FetchType.EAGER) + private CEntity eagerC; + @OneToMany( fetch = FetchType.LAZY, mappedBy = "c", @@ -419,6 +434,14 @@ public class LoadAndFetchGraphTest extends BaseEntityManagerFunctionalTestCase { this.c = c; } + public CEntity getEagerC() { + return eagerC; + } + + public void setEagerC(CEntity eagerC) { + this.eagerC = eagerC; + } + public List getdList() { return dList; }