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]