-->
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: Partial fetching of collection?
PostPosted: Sun Aug 05, 2012 9:29 am 
Beginner
Beginner

Joined: Sun Apr 25, 2010 7:14 am
Posts: 30
Hi together,

i would like to fetch only parts of the a collection using a hibernate criteria query. As an example lets say i have a Class object containing multiple Student objects. Now i would like to get a list of classes but only the german students should be fetched into the students collection (the rest is not needed and would be massive overhead) with just one database query.

In later versions of hibernate (i think before 3.6.4) this could be done by using a filtered createCriteria like this:
Code:
criteria.createCriteria("students", "studentscollection", Criteria.LEFT_JOIN, Restrictions.eq("studentscollection.country", "DE"));

The problem is that in current versions of hibernate this leaves the collection uninitialized and triggers massive database queries to load the whole collections for every single collection on access. This is a massive performance problem causing hundreds of queries instead of one.

Is there any solution in current hibernate versions to get this done using one query?

Thanks a lot!

Yours
Thomas


Top
 Profile  
 
 Post subject: Re: Partial fetching of collection?
PostPosted: Thu Aug 16, 2012 4:06 am 
Beginner
Beginner

Joined: Sun Apr 25, 2010 7:14 am
Posts: 30
No answer means that it is not possible?


Top
 Profile  
 
 Post subject: Re: Partial fetching of collection?
PostPosted: Wed Nov 07, 2012 4:18 am 
Regular
Regular

Joined: Thu Nov 13, 2003 2:55 am
Posts: 71
Location: Sweden
Would it be possible for you, to query the German students instead (and implicitly find their classes)?


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.