Hibernate HSQL syntax for Associations

W

wls

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, (e-mail address removed)
http://www.wwco.com/~wls/
 
R

rico.fabrini

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?

It's called HQL (not HSQL)

I would suggest:
"from X as x join x.collection as y where y.something = :something1"

Rico.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top