属性不在的休眠条件(子查询) [英] Hibernate Criteria With Property Not In (Subquery)
本文介绍了属性不在的休眠条件(子查询)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想执行类似的查询
Select id, name from information where name not in (select firstname from contact where id = 1)
Information
Id Name
1 Test
Contact
id firstname
1 name
2 Test
如果我使用 neProperty() 函数,它将返回记录为 name != Test.
If I am using neProperty() function, it will returns records as name != Test.
如何使用休眠条件实现?
How can I implement using hibernate criteria?
谢谢
推荐答案
创建全选条件:
Criteria cr = session.createCriteria(Your.class);
List list = cr.list();
然后您可以对其添加限制,即第 1 列 = 8 等,如下所示:
Then you can add you restriction to it, i.e. where column 1=8 etc like this:
cr.add(Restrictions.eq("YourCondition", YourCondition));
最后,您可以像这样提供 not in 子句:
Finally, you can provide the not in clause like this:
cr.add(Restrictions.not(Restrictions.in("YourNotInCondition", YourNotInCondition)));
这篇关于属性不在的休眠条件(子查询)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文