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; }