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: Load Entity w/ Subset of Collection
PostPosted: Sun Oct 26, 2008 5:43 pm 
Newbie

Joined: Thu Dec 14, 2006 7:08 pm
Posts: 11
Hi,

How do I write a criteria query that retreives a single parent with a subset of the partent's children that have specific friends ?

For example,

Parents: Meg, Emily

Meg's Children: Sarah, Steve, Bo
Emily's Children: Marsha

Sarah's Friends : Tim, Jane
Steve's Friends : Tim
Bo's Friends : Alice

I would like to load Meg with only the children who have Tim as a friend.
In which case I would get Meg with only Sarah and Steve loaded.

So far my query is,

ICriteria ParentCrit = CurrentSession.CreateCriteria(typeof(Parent));
ICriteria ChildrenCrit = ParentCrit.CreateCriteria("Children");
ICriteria FriendsCrit = ChildrenCrit.CreateCriteria("Friend");

ParentCrit.Add(Expression.Eq("Id", "Meg"));
FriendsCrit.Add(Expression.In("Name", new object {"Tim"}))
.SetResultTransformer(CriteriaUtil.AliasToEntityMap);


When I call ParentCrit.List() I get a hash table with two identical Parent objects and their entire collection of children loaded. What do I need to change?

Thanks for reading.

Cheers,
Aeden


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2008 11:32 pm 
Newbie

Joined: Thu Dec 14, 2006 7:08 pm
Posts: 11
anyone?


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.