问题
How to write this query in HQL:
select * from Employee where Emp_Code
NOT IN (select Emp_Code from EmployeeAllocation);
I was unable to find any solution for this on google. I dont know how to write NOT IN clause in HQL The result should must be fetched to a List. Like this:
List<String> lst = query.list();
回答1:
I think you can do it like, As you haven't provided any information about the table structure, otherwise I would have suggested you some better query.
But here in the below shown query I am just trying to tell you about the NOT IN clause in Hibernate or hql.
list = select Emp_Code from EmployeeAllocation
Criteria criteria = DetachedCriteria.forClass(Employee.class);
criteria.add(Restrictions.not(Restrictions.in("Emp_Code", list);
return getHibernateTemplate().findByCriteria(criteria);
来源:https://stackoverflow.com/questions/9416974/not-in-clause-in-hql