See the attached test case.
The relevant part is bytecode enhancement in the pom file, and LazyCollectionOption.EXTRA in ParentEntity:
{ { code:java} @Entity public class ParentEntity { ... @OneToMany(cascade = CascadeType.ALL, mappedBy = "parent") @LazyCollection(LazyCollectionOption.EXTRA) private Set<ChildEntity> children = new HashSet<>(); ... } {code } }
The actual output shows that ParentEntity.children is initialized with all children:
{noformat} Hibernate: select parententi0_.id as id1_1_ from ParentEntity parententi0_ Hibernate: select children0_.parent_id as parent_i2_0_1_, children0_.id as id1_0_1_, children0_.id as id1_0_0_, children0_.parent_id as parent_i2_0_0_ from ChildEntity children0_ where children0_.parent_id=? {noformat} The expected output should show that only the number if children is queried:
{noformat} Hibernate: select parententi0_.id as id1_1_ from ParentEntity parententi0_ Hibernate: select count(id) from ChildEntity where parent_id =? {noformat}
Suggested fix is to delay initialization in AbstractEntityPersister.initializeLazyProperty for extra-lazy collections:
{ { code:java} // Initialize it unless it is extra lazy if ( !persister.isExtraLazy() ) { session.initializeCollection( collection, false ); } interceptor.attributeInitialized( fieldName ); {code } }
The suggested fix will show the expected output. |
|