I have a common situation with parent-child relation like:
class Parent {
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
List<ChildOne> childrenOne;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
List<ChildTwo> childrenTwo;
@OneToMany
List<LazyChild> lazyChildren;
@Id
Long id;
}
Then I have the HQL query like:
select lazyChild from Parent p
join p.lazyChildren lazyChild
where p.id = ? and lazyChild.mnemonic='AAA'
When I execute it I get LazyChild object and it's what I want. But hibernate also initialize all eagerly defined collections and it's what I don't want. It's not intuitive that hibernate makes a separate call to fetch eager associations. I see it by switching to show SQL query.
How to avoid that unnecessary SQL calls?