Hibernate Criteria Restrictions AND/OR 组合 [英] Hibernate Criteria Restrictions AND / OR combination

查看:39
本文介绍了Hibernate Criteria Restrictions AND/OR 组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何使用 Hibernate Restrictions 实现这一目标?

How would I achieve this using Hibernate Restrictions?

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

推荐答案

think works

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));

这篇关于Hibernate Criteria Restrictions AND/OR 组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆