Hi all,
I have a many-to-many mapping and want a Criteria query
using the Example class. But I don't know how to formulate
the query.
I found this posting
http://forum.hibernate.org/viewtopic.ph ... y&start=15
which ends with no result. I tried the suggested way in the posting and ended also with a scrambled SQL query.
Is there a way to do it?
To be more specific: I have:
table x
table y
and table xy for the many-to-many mapping.
I try:
[code]
Criteria criteria = session.createCriteria(X.class,"x");
Set set = x.getYs();
Iterator iter = set.iterator();
while(iter.hasNext()){
Y y = (Y)iter.next();
Long id = y.getId();
DetachedCriteria dc = DetachedCriteria.forClass(X.class, "x2")
.setProjection(Property.forName("id")).createCriteria(
"ys", "s").add(Restrictions.idEq(id)).add(
Property.forName("x2.id").eqProperty("x.id"));
criteria = criteria.add(Subqueries.exists(dc));
}
List result = criteria.list();
[/code]
I don't know if this is the right query: I want instances of x
where y.attr1=value1 and y.attr2=value2 (these are set in y)
Please help.
Thanks, Heike
--
I am using hibernate 3.1 with postgreSQL