-->
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: HQL - selecting parent of a collection with common property
PostPosted: Mon Sep 18, 2006 3:12 pm 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
Hi, everyone!
I am trying to create a query that is simpler said than done. There are two entities, A and B, with a bidirectional many-to-one relationship. I want to select all instances of A for which all B have a boolean property equal to true. My best try was this one, but it failed returning as many repeated instances of A as there were B with that property equal to true.
Code:
select a from A join a.b b where b.someProp = true

This query clearly does not contain as much information as I want, but I don't know how to do it. Should I use some cross products?

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 4:45 am 
Newbie

Joined: Wed Oct 05, 2005 3:36 am
Posts: 15
select DISTINCT a from A join a.b b where b.someProp = true


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 7:20 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
Yes, but that gives me all A for which any B.someProp is true. I need all B.someProp to be true. Like this:
Code:
A1
  b[0].someProp = false
  b[1].someProp = true
A2
  b[0].someProp = true
  b[1].someProp = true


I want to select A2 but not A1. After the first post I found a way to do this with five cross-products since A2 has a discriminator attribute with five possible values. But is there a shorter way?

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 12:00 pm 
Newbie

Joined: Wed Oct 05, 2005 3:36 am
Posts: 15
FROM a WHERE true = ALL (SELECT b.someProp FROM b WHERE b.a = a)


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.