小编典典

Hibernate条件限制和/或组合

hibernate

如何使用hibernate限制来实现此目的?

(((A='X') and (B in('X',Y))) or ((A='Y') and (B='Z')))

阅读 441

收藏
2020-06-20

共1个答案

小编典典

认为有效

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));
2020-06-20