Restrictions.conjunction() and disjunction() let you add as many Criterions as you want, e.q.:
Code:
Criteria c = s.createCriteria(Customer.class);
Conjunction c1 = Restrictions.conjunction();
c1.add(Restrictions.eq("someProperty", 1)).add(Restrictions.eq("someProperty2", 2)).add(Restrictions.eq("someProperty2", 2));
Conjunction c2 = Restrictions.conjunction();
c2.add(Restrictions.eq("someProperty", 1)).add(Restrictions.eq("someProperty2", 2));
c.add(Restrictions.disjunction().add(c1).add(c2));
c.list();
Results in
Quote:
select
this_.id as id1_0_,
this_.someProperty as someProp2_1_0_,
this_.someProperty2 as someProp3_1_0_,
this_.toOne_id as toOne4_1_0_
from
Customer this_
where
(
(
this_.someProperty=?
and this_.someProperty2=?
and this_.someProperty2=?
)
or (
this_.someProperty=?
and this_.someProperty2=?
)
)
Which is what you want.
Rating appreciated. ;-)