-->
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: Possible to tell parent not to load non matching siblings?
PostPosted: Tue Aug 05, 2008 11:44 am 
Newbie

Joined: Tue Jul 22, 2008 4:35 pm
Posts: 1
I have a one-to-many association and want to be able to filter the children (by searching on them) and still be able to iterate over the parents with only the appropriate children present.

So basically I have this. Three kids aged 8, 9, and 11.

Code:
Criteria criteria = session.createCriteria(Parent.class);
criteria.createCriteria("children").add(Expression.gt("age", new Integer(10)));
return criteria.list();


If I execute the SQL it generates, there is only one record returned, which is correct and what I want. But if I iterate through the returned Parent object, it outputs all three kids (and I know why it does, it doesn't care about my filtering).

Is there a way to prevent the parent object from loading the children that do not match the criteria?

I'm using Spring 2.5 and Hibernate Core 3.2.6.ga


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 2:38 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
There is an example of this in the documentation (http://www.hibernate.org/hib_docs/v3/re ... sociations) though I am not very familiar with the Criteria API and can't say that I fully understand what is happening. I guess though that it is only if you access the child collection through the map that it is filtered. If you access it through the parent object it will still contain all children.

The information in http://www.hibernate.org/hib_docs/v3/re ... -filtering may also be useful.


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.