Hello,
This question has been asked multiple times on this forum but nobody seems to have a clear answer.
I have a class (A) which has 3 sets of other classes (B, C and D) (one-to-many). These classes have a many-to-one relationship with another class (E).
Code:
B
/ \
/ \
/ \
A - - - C - - - E
\ /
\ /
\ /
D
What I'm trying to accomplish is to load one object of class A and eagerly load all it's references to B, C and D which in their turn have to eagerly load all their references to E.
I've tried to solve this with a Criteria, but that seemed to be impossible. Then I tried this HQL statement:
Code:
from A a1
left join fetch a1.B as b1
left join fetch b1.e as e1
left join fetch a1.C as c1
left join fetch c1.e as e2
left join fetch a1.D as d1
left join fetch d1.e as e3
where a1.number = :number
This seems to work but it generates an enormous amount of overhead because of the cartesian product problem.
What I actually want to do is to instantiate the object of class A using 3 queries, one for each Set. However I haven't found a way to do this.
I'm also considering to keep my session open and use Hibernate.initialize on the Sets, but this will generate a lot of overhead to which is not something I want.
Can somebody help me with this problem?[/code]