-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: 3-level (1->2->3) HQL eager fetching
PostPosted: Mon Dec 18, 2006 9:29 am 
Newbie

Joined: Mon Aug 07, 2006 2:35 pm
Posts: 7
Location: Poland
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


Top
 Profile  
 
 Post subject: Solved: 3-level (1->2->3) HQL eager fetchin
PostPosted: Mon Dec 18, 2006 12:14 pm 
Newbie

Joined: Mon Aug 07, 2006 2:35 pm
Posts: 7
Location: Poland
Problem solved.
Quote:
Another idea: is it possible having list of ent2 (first query result) load their children in one query for all ent2?[/b]

was right approach and has been implemented by adding batch-size to ent2->ent3 one-to-many mapping.

regards,
Andriy Korud


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.