-->
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: How to retrieve only certain child elements in a collection?
PostPosted: Thu Mar 13, 2008 5:26 pm 
Newbie

Joined: Thu Mar 13, 2008 12:20 pm
Posts: 3
Hi Guys,

Sorry if this is a really obvious question. I've been through the docs and have the Java Persistence with Hibernate book, but can't seem to find a simple way of doing what I need.

Basically I have a class AccomType, which has a collection of Room objects. I want to retrieve all my AccomType's and their associated Room objects, but only where Room has a certain status attribute set. But I want to retrieve ALL AccomTypes (even those with no applicable Room objects)

From what I've read, I need to create a query something like

from AccomType a left join a.Rooms r with r.status=0

but the results are an Array with with first element of AccomType, and the 2nd the Rooms. While this is correct, and I could write a bit of code to assemble them into an AccomType object, is there no way of doing it so that it I can get it all back in one go?

Thanks,
Al


Top
 Profile  
 
 Post subject: Re: How to retrieve only certain child elements in a collect
PostPosted: Thu Mar 13, 2008 5:31 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
How about:

Code:
select distinct a from .....



Farzad-


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.