I've got a one-to-many association between two entities, X and Y.
class X {
@OneToMany( cascade = CascadeType.ALL )
private List<Y> collection = new ArrayList<Y>();
}
What's the HSQL notation to return any X who's collection contains a Y
with a specific property?
In SQL, I'd do a join between X and Y where Y.whatever = value.
However, I think I'm using the wrong terminology, as I can't seem to
find an example in the Hibernate Reference Documentation (version
3.2.5).
So, I backed off and tried just finding if a thing was in a
collection, using:
List<X> found = session.createQuery( "from X x where :y in
( x.collection )" ).setEntity( "y", y ).list();
Naturally this gives me syntax error.
Can anyone point me in the right direction?
Thanks in advance,
-Walt Stoneburner, wls@wwco.com
http://www.wwco.com/~wls/
rico.fabrini@gmail.com - 04 Oct 2007 03:19 GMT
> I've got a one-to-many association between two entities, X and Y.
>
[quoted text clipped - 6 lines]
> What's the HSQL notation to return any X who's collection contains a Y
> with a specific property?
It's called HQL (not HSQL)
I would suggest:
"from X as x join x.collection as y where y.something = :something1"
Rico.