我想建立查询在游戏框架,我有

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

候选和学校的关系是在链接表中。

是否有任何方式结合多个值?

有帮助吗?

解决方案

使用休眠,也可以直接使用列表本身。

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

的类型的:学校参数根据你的id类型的,例如List<Int>List<Long>

其他提示

事实上,我发现问题的所在 - 的构件只能与单个值一起使用,并且工作正常。当我们需要使用多个值最好是使用标准的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 /休眠/参考/ EN / HTML / queryhql.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top