2010-09-28 172 views
3

結合休眠多個值我想在遊戲框架來構建查詢,我有使用播放框架

select * from Candidate c where (:schools member of c.schools) 

我綁定後:用返回結果的一個元素列表學校,但如果我綁定列表與多個元素都沒有發生。

Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: {vector} [select c from models.Candidate c where (:schools0_, :schools1_ member of c.schools) group by c.id order by RAND()] 

其實我需要這樣的東西候選人與學校之間

select * from candidate where schools in (x,x,x,x,x); 

關係是鏈接表。

有什麼辦法可以綁定多個值嗎?

回答

1

使用Hibernate,你也可以直接使用列表本身。

select c from Candidate c join c.schools as school where school.id in (:schools) 

的類型組成:學校參數根據你的id類型的,例如List<Int>List<Long>

4

其實我發現問題所在 - 的成員只能用於單個值,並且工作正常。當我們需要使用多個值最好是使用標準的SQL

select c from Candidate c inner join c.schools as school where school.id in (25980,25981)" 

加入鏈接的表是必需的 - 我們不能使用c.schools.id,所以我們需要內將C 。別名的.schools指定列。

我認爲所有的初學者應該檢查http://www.javatx.cn/hibernate/reference/en/html/queryhql.html