-->
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.  [ 4 posts ] 
Author Message
 Post subject: Query a collection of collections!
PostPosted: Wed May 14, 2014 5:53 pm 
Newbie

Joined: Thu Apr 17, 2014 1:21 pm
Posts: 5
I'm sure this question has been asked before but I can't seem to find an answer on these forums.

I am trying to get a collection of objects from a grandparent object.
This is the basic setup:

Code:
Class Clinic{
     Set<Owner> owners;
}

Code:
Class Owner {
     Set<Pet> pets;
}


I want to get all the pets from a Clinic. So something along the lines of
Code:
select clinic.owners.pets where clinic.id = :id


clinic.owners.pets won't work because of "dereferencing a collection" exception

I also tried something like
Code:
select o.pets from owner o join c.owners with clinic c where c.id = :id


That didn't work either


Top
 Profile  
 
 Post subject: Re: Query a collection of collections!
PostPosted: Wed May 28, 2014 9:42 am 
Newbie

Joined: Thu Apr 17, 2014 1:21 pm
Posts: 5
I'm still having trouble with this query if anyone has any input it would be greatly appreciated


Top
 Profile  
 
 Post subject: Re: Query a collection of collections!
PostPosted: Wed May 28, 2014 10:30 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
I would try something like:

Code:
SELECT p
FROM Clinic as c
              INNER JOIN c.owners as o
              INNER JOIN o.pets as p
WHERE c.id = :id


Davide


Top
 Profile  
 
 Post subject: Re: Query a collection of collections!
PostPosted: Wed May 28, 2014 10:38 am 
Newbie

Joined: Thu Apr 17, 2014 1:21 pm
Posts: 5
DAVIDE,

I love you. This works perfectly :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.