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
Criteria criteria = session.createCriteria(UserImpl.class,"user"); criteria.add(Restrictions.not(Restrictions.in("nameOfFieldInWhichYouAreStoringAffectedPersons", affectedPersons)));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.