2011-04-06 44 views
5

中發揮聲明我怎麼能寫一個HQL查詢關鍵詞,比如同一個SQL查詢是這樣的:「中的」使用HQL

select * from Users u where u.id in (1, 3, 4) 
+0

也許這將幫助你: http://stackoverflow.com/questions/961816/proper-way-of-writing-a-hql-查詢中使用JPA的另一個例子:http://stackoverflow.com/questions/4828049/in-clause-in-hql-or-java-persistence-query-language我從來沒有使用hql,但它總是有助於谷歌一點點 :) – Steven 2011-04-06 06:56:02

回答

0

嘗試User.find("id in (:ids)").bind("ids", new Long[]{1L,3L,4L}).fetch()

0

我建議你使用本地查詢利用你的SQL查詢,這樣你就不必轉換成HQL。

0

與發揮做到這一點最簡單的方法是

public static void findByIds(List<Long> userIds) { 
    find("from Users u where u.id in (?1)", userIds).fetch(); 
}