-->
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: Matching elements in 2 collections
PostPosted: Tue May 08, 2007 12:17 pm 
Newbie

Joined: Tue Mar 02, 2004 2:22 am
Posts: 5
I'm trying to come up with a HQL query that gives me the cartesian join of 2 tables filtered by the occurrence of the same element in 2 collections. I've been reading through the docs over and over but can't see the solution for this.

To illustrate, suppose 2 classes:

Code:
class Beer {
    Set<String> bottleSizes;
}
class Wine {
    Set<String> bottleSizes;
}


and suppose I want to get all Beer objects for which there is Wine object w/ an equivalent bottleSize (don't ask me why!).

The mappings use simple <set> w/ bottleSize as String element, like this:

Code:
<class name="Beer">
  ...
  <set name="bottleSizes" cascade="all">
    <key column="beer_id"/>
    <element column="bottleSize" type="string"/>
  </set>
</class>
<class name="Wine">
  ...
  <set name="bottleSizes" cascade="all">
    <key column="beer_id"/>
    <element column="bottleSize" type="string"/>
  </set>
</class>


So, the query I dream of is something like:

Code:
SELECT b FROM Beer b, Wine w
WHERE elements(b.bottleSizes) = some elements(b.bottleSizes)


Any insights on how can I achieve it?[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 12:50 pm 
Newbie

Joined: Tue Mar 02, 2004 2:22 am
Posts: 5
It helps to think about beers and wines.. and re-check the docs. This query does what I want:

Code:
SELECT DISTINCT b FROM Beer b LEFT OUTER JOIN b.bottleSizes AS size, Wine w
WHERE size IN elements(w.bottleSizes)


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.