简体   繁体   English

在Hibernate条件限制中使用所选对象

[英]Using selected object in Hibernate criteria restriction

I am trying to rewrite a query: 我正在尝试重写查询:

select user from UserImpl as user where user not in (:affectedPersons)

With a Hibernate Criteria as: 休眠标准为:

createCriteria(UserImpl.class, "user").add(Restrictions.not(Restrictions.in("user", affectedPersons))));

But I get Hibernate exception saying: 但我得到休眠的异常说:

'user' field is not found in UserImpl entity

I understand the exception but I can't find the way how to use/specify 'user' alias of selected object to make it available in criteria restriction. 我了解例外情况,但找不到如何使用/指定所选对象的“用户”别名以使其在条件限制中可用的方法。

Thank you in advance. 先感谢您。

Here You have to give the Column/field not(Restrictions.in("user"), It will search for the field user in UserImpl , which it will not find. That is why it is giving error 在这里,您必须给Column / field not(Restrictions.in(“ user”)),它将在UserImpl中搜索找不到的字段user,这就是为什么它给出错误的原因

Criteria criteria = session.createCriteria(UserImpl.class,"user"); 条件标准= session.createCriteria(UserImpl.class,“ user”); criteria.add(Restrictions.not(Restrictions.in("nameOfFieldInWhichYouAreStoringAffectedPersons", affectedPersons))); 条件.add(Restrictions.not(Restrictions.in(“ nameOfFieldInWhichYouAreStoringAffectedPersons”,受影响的人)));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM