-->
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: Query for parents based on the child condition
PostPosted: Fri May 22, 2009 6:59 am 
Newbie

Joined: Fri May 22, 2009 6:48 am
Posts: 2
Hi,

Let us say that I have a Parent-Child relationship, where one Parent can have multiple Children.
Parent object has a collection of Child objects.

Is it possible to query for all Parents that have certain children (children older than 16 years)?
What I would like to get by the Hibernate is a collection Parent objects (matching the above condition) with their children collection populated only with those children that are matching the above condition.

For the following example:

Parent 1 (Child 1a (15yrs), Child 1b (10yrs))
Parent 2 (Child 2a (18yrs), Child 2b (9yrs))
Parent 3 (Child 3a (11yrs), Child 3b (20yrs), Child 3c (19yrs))


The result should be a collection of Parent objects initialized as:

Parent 2 (Child 2a (18yrs))
Parent 3 (Child 3b (20yrs), Child 3c (19yrs))


Is it possible to create such mapping/query in Hibernate and how?

Regards


Top
 Profile  
 
 Post subject: Re: Query for parents based on the child condition
PostPosted: Fri May 22, 2009 8:08 am 
Newbie

Joined: Fri May 22, 2009 6:48 am
Posts: 2
Hi,

I just realized that a filter (on a collection level) is most suitable for this purpose.

If you have any other suggestions, please advise.

Thanks


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.