-->
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.  [ 3 posts ] 
Author Message
 Post subject: JPA Join Fetch Question
PostPosted: Mon Sep 24, 2007 9:20 pm 
Newbie

Joined: Mon Sep 24, 2007 9:00 pm
Posts: 1
I am working on a spring jpa application that uses hibernate 3.2.0.GA.

My question has to do with the join fetch option in a jpa query. The situation I have is there are MANY records in the database and the query could potentially return a large number of results.

Tuning on the sql seems to indicate the query prepares quickly and returns rows quickly. I have a one-to-many relationship. I am limiting the number of results that are returned using the setMaxRetulst option:

Code:
q.setMaxResults(maxRows);

I want to display the child records of the one-to-many, so in my original query I used:

Code:
left outer join fetch


What I have found is this takes a really long time to return. If I switch this to not fetch join; the query runs in a reasonable about of time, although it runs N+1 queries to fetch the child records. I’m wondering if the “fetch” join requires that all the records be processed due to ordering issues? Is there a way (maybe a hint) to avoid this issue since in my case the records will be coming in order?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 11:29 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Do it in 2 queries:
load the main object (not the associated ones) and limit the number of results.

Then load the associated objects by a select ao from AssociatedObject as where id in (:associtedObjectsIds)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 11:30 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Or use fetch subselect (static mapping not HQL) which should do just that

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.