[英]Error using Spring, Play Framework, Hibernate and MySql
[英]binding multiple values in hibernate using play framework
我试图在Play框架中构建查询,我有
select * from Candidate c where (:schools member of c.schools)
在我绑定之后:带有一个元素的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);
候选人和学校之间的关系在链表中。
有没有办法绑定多个值?
实际上我找到了问题所在 - 成员只能使用单值,并且工作正常。 当我们需要使用多个值最好是使用标准的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
使用Hibernate,您还可以直接使用列表本身。
select c from Candidate c join c.schools as school where school.id in (:schools)
:schools参数的类型根据您的ID键入,例如List<Int>
或List<Long>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.