-->
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: Retrieving parents with specific 'grand children'
PostPosted: Fri Apr 30, 2010 8:52 pm 
Newbie

Joined: Fri Apr 30, 2010 8:38 pm
Posts: 1
Hello all,

I am very new to Hibernate, so this has been stumping me for the past few days. Suppose you have a person, that has dogs, who have toys:

Code:
Person A
   Dog 1
      Toy - Red
      Toy - Green       
   Dog 2
      Toy - Red
      Toy - Green

Person B
   Dog 1
      Toy - Blue
      Toy - Green       
   Dog 2
      Toy - Blue
      Toy - Green


I want to retrieve only the People that have dogs that have RED toys. I also only want to retrieve the RED toys, so the result would be:

Code:
Person A
   Dog 1
      Toy - Red     
   Dog 2
      Toy - Red


I have no idea how to do this. I need to send it a list of colors. I have tried:
Code:
Criteria criteria = this.getSession().createCriteria( Person.class ).createCriteria("dogs")
         .createCriteria("toys").add( Expression.in(toy_color, colors) ); //where colors is a List of colors


and also many other combos that I can't remember. I'm like a chicken with my head cut off here, and I honestly don't know how to get the specific grandchildren, just those grandchildren, and their parent and grandparent. All tutorials are for only one level of children.

Does anyone know how to do this, or at least know of a relevant tutorial?

Thanks so much!


Top
 Profile  
 
 Post subject: Re: Retrieving parents with specific 'grand children'
PostPosted: Mon May 03, 2010 8:32 am 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
Hi,

What result does the example query that you showed produce?

--
Stephen


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.