Hibernate标准的属性不在(子查询) [英] Hibernate Criteria With Property Not In (Subquery)

查看:157
本文介绍了Hibernate标准的属性不在(子查询)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行查询类似于

 选择id,名称来自其中名称不在其中的名称id = 1)

信息
Id名称
1测试

联系
id名字
1名称
2 Test

如果我使用neProperty()函数,它将返回记录为 name!= Test。



如何使用hibernate标准实现?

感谢

解决方案

创建一个全选标准:

  Criteria cr = session.createCriteria(Your.class); 
List list = cr.list();

然后,您可以添加限制条件,即列1 = 8等。 p>

  cr.add(Restrictions.eq(YourCondition,YourCondition)); 

最后,您可以提供not in子句,如下所示:

  cr.add(Restrictions.not(Restrictions.in(YourNotInCondition,YourNotInCondition))); 


I want to execute query something like

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

If I am using neProperty() function, it will returns records as name != Test.

How can I implement using hibernate criteria?

Thanks

解决方案

Create a select-all criteria:

Criteria cr = session.createCriteria(Your.class); 
List list = cr.list(); 

Then you can add you restriction to it, i.e. where column 1=8 etc like this:

cr.add(Restrictions.eq("YourCondition", YourCondition));

Finally, you can provide the not in clause like this:

cr.add(Restrictions.not(Restrictions.in("YourNotInCondition", YourNotInCondition)));

这篇关于Hibernate标准的属性不在(子查询)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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