Hi,
I have the following database structure (Hibernate 3.1.2):
ent1----->ent2----->ent3
with average proportion 1->10->10 (i.e. each
ent1 has 10 children of
ent2 having 10 children of
ent3).
ent2 has many-to-one mapping to
ent1 and one-to-many to
ent3.
I'm trying to select
ent2 with some criteria (not important) using HQL and wonder if it is possible to get ALL data in one query?
Currently, code
Code:
from Ent2 as ent2 left join fetch ent2.parent where...
fetch all
ent2 and
ent1, followed by separate SQLs for reading children (
ent3) for each
ent2 (typical n+1 problem, in my case n>100).
Following straightforward query
Code:
from Ent2 as ent2 left join fetch ent2.parent left join fetch ent2.children where...
produces multiplication -
ent2 is duplicated for each
ent3
Is there right pattern optimal from performance point of view for such problem?
Another idea: is it possible having list of
ent2 (first query result) load their children in one query for all
ent2?[/b]
thanks in advance,
Andriy