-->
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: filtering mapped collection
PostPosted: Mon Aug 13, 2007 8:34 am 
Newbie

Joined: Tue Jul 12, 2005 6:55 pm
Posts: 9
Hi all,

Is there any way to filter entity's mapped collection? I have AnObject having a collection of AChildObject. I'd like to make a query (preferably criteria-based, but HQL is acceptable) returning list of AnObject with prefetched AChildObject collections, but not all of children - a subset of them. So I can use AnObject.getChildren() without issuing additional queries to the DB and get subset of childrens...

I hope I managed to be clear enough ;-) Any help (or suggestion of alternative approach for effective obtaining a list of items with filtered related objects) will be greatly appreciated.

Wojtek


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 5:48 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
You can add filtering using hql but not criteria.
e.g.
from AnObject anobj join fetch anobj.childObjects children where children.name ='anna'

However, this returns an incomplete representation of your object (which is what you want) so persisting any modifications to the returned object could result in the deletion of the children that were filtered out (depending on cascade settings).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 13, 2007 6:12 pm 
Newbie

Joined: Tue Jul 12, 2005 6:55 pm
Posts: 9
Thanks :-)


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.