2012-02-23 22 views
0

條款如何寫HQL這個查詢:並非在HQL

select * from Employee where Emp_Code 
NOT IN (select Emp_Code from EmployeeAllocation); 

我無法找到谷歌這方面的任何解決方案。 我不知道如何在HQL中編寫NOT IN子句 結果應該被提取到列表中。就像這樣:

List<String> lst = query.list(); 
+0

http://stackoverflow.com/questions/1220901/how-to-achieve-not-in-by-using-restrictions-and-criteria-in-hibernate – 2012-02-23 16:32:39

+1

你看了關於HQL的參考手冊? HQL查詢將非常類似於SQL。您只需使用別名,實體名稱而不是表名稱,而使用屬性名稱而不是列名稱。 HQL適用於實體。由於我們不知道你的實體是什麼,我們無法回答。 http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#queryhql – 2012-02-23 17:01:27

+0

實體業者名稱 員工:員工 Employee_Allocation:分配 屬性 - Emp_Code在員工:empCode Emp_Code已分配:employeeCode – user1228826 2012-02-23 18:01:59

回答

0

我認爲你可以不喜歡它,當你沒有提供有關表結構的任何信息,否則,我會建議你一些更好的查詢。

但是,在下面顯示的查詢中,我只是想告訴你關於Hibernate或hql中的NOT IN子句。

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);