Hibernate version: 3.0
Hello,
I'm looking for a Criteria based solution in Hibernate 3 for a query that accesses a many-to-one association where
- either a condition on that association is true
- or the association is null
I succeeded in creating two separate criteria objects, one for each case:
Code:
List list1 =
session.createCriteria(Foo.class)
.setProjection(Projections.property("column"))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.createCriteria("association")
.add(Restrictions.eq("val", new Integer(myVal)))
.list();
List list2 =
session.createCriteria(Foo.class)
.setProjection(Projections.property("column"))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.add(Restrictions.isNull("association"))
.list();
My desired result is in this case the union of these two lists.
However, I'm clueless how to construct these conditions in *one* criteria. This becomes necessary when I want to apply my condition on more than one association.
Can anybody direct my in the right direction?
Thanks in advance,
Oliver