Hibernate Criteria Restrictions AND / OR combination

前端 未结 2 1869
Happy的楠姐
Happy的楠姐 2020-11-30 19:50

How would I achieve this using Hibernate Restrictions?

(((A=\'X\') and (B in(\'X\',Y))) or ((A=\'Y\') and (B=\'Z\')))
2条回答
  •  鱼传尺愫
    2020-11-30 20:08

    think works

    Criteria criteria = getSession().createCriteria(clazz); 
    Criterion rest1= Restrictions.and(Restrictions.eq(A, "X"), 
               Restrictions.in("B", Arrays.asList("X",Y)));
    Criterion rest2= Restrictions.and(Restrictions.eq(A, "Y"), 
               Restrictions.eq(B, "Z"));
    criteria.add(Restrictions.or(rest1, rest2));
    

提交回复
热议问题