hi,
I solved the problem using a Criteria and 2 DetachetCriteria
Code:
DetachedCriteria subQueryNotExists = DetachedCriteria.forClass(MyTable.class, "tab1")
.add(Property.forName("tab1.val1").eqProperty("tab2.val1"))
.add(Property.forName("tab1.val2").eqProperty("tab2.val2"))
.add(Restrictions.isNotNull("tab1.refId"))
.setProjection(Projections.id());
DetachedCriteria subQueryIn = DetachedCriteria.forClass(MyTable.class, "tab2")
.add(Property.forName("tab2.val1").eqProperty("tab3.val1"))
.add(Property.forName("tab2.val2").eqProperty("tab3.val2"))
.add(Restrictions.isNull("tab2.refId"))
.add(Subqueries.notExists(subQueryNotExists))
.setProjection(Projections.max("tab2.id"));
Criterion cr = Restrictions.isNotNull("tab3.refId");
cr = Restrictions.or(cr, Property.forName("tab3.id").in(subQueryIn));
Criteria criteria = getSession().createCriteria(MyTable.class, "tab3");
criteria.add(Restrictions.like("tab3.val1", val1, matchMode));
criteria.add(Restrictions.like("tab3.val2", val2, matchMode));
criteria.add(cr);
thanks anyway
bye