views:

71

answers:

1

I am trying to build query in Play framework, I have

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

After I bind :school with List with one element it returns result, but if I bind List with multiple elements nothing happens.

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()]

Actually I need something like

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

Relation between candidate and school is in linked table.

Is there any way to bind multiple values?

+3  A: 

Actually I found where the problem is - member of can be used only with single value and it works fine. When we need to use multiple values the best is to use standard sql in:

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

Joining the linked tables is required - we can't use c.schools.id, so we need to inner join c.schools with alias to specify the column.

I think all beginners should check http://www.javatx.cn/hibernate/reference/en/html/queryhql.html

Georgi