我正在尝试在Play框架中建立查询,

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

在将:school与List绑定到一个元素后,它返回结果,但是如果我将List与多个元素绑定,则什么也没有发生。
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);

候选人与学校之间的关系在链接表中。

有什么办法可以绑定多个值?

最佳答案

使用Hibernate,您还可以直接使用列表本身。

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

:schools参数的类型是根据您的ID键入的,例如List<Int>List<Long>

08-28 19:02