-->
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: Help? Criteria (or HQL) based on collection member property?
PostPosted: Thu Sep 02, 2010 4:48 pm 
Beginner
Beginner

Joined: Tue Feb 03, 2009 4:33 pm
Posts: 21
Hi all,

I need to submit a hibernate Query (HQL or criteria-based), that will query on some property of an object in an entity's member collection. I'm probably not using the terminology correctly, but to use the HQL reference manual's ubiquitous Cat/Kitten example, I basically need the Hibernate equivalent of:

Code:
Select distinct cat from Cat cat where cat.kittens.name is not null


This is completely wrong of course, but the goal would be to return a list of cats that have at least one kitten whose name is not null.

Can anyone tell me how to do this? It's dead simple in SQL, but I can't figure it out using session.CreateCriteria (or HQL, for that matter).

thanks!


Top
 Profile  
 
 Post subject: Re: Help? Criteria (or HQL) based on collection member property?
PostPosted: Thu Sep 02, 2010 7:05 pm 
Newbie

Joined: Wed Apr 30, 2008 10:03 am
Posts: 4
AFAIK Criteria queries are useless for collection conditions, they see collections as second-level (i.e. not relation) dbzens.

Try something like

Code:
select distinct cat from Cat cat
  left join cat.children as child
where child.name is not null


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.