I'm trying to 开发者_Go百科make a query in HQL that see if the id of a person is in a list of predefined ids.
For example, I would like to find all persons that have id 1 or 2 in a database.
The problem is that I cannot do: from Person person where id in elements(:ids) because elements expects an identifier (like person.childIds for example) and not a named parameter.
Is there a way to do this without resorting to parse de List and create the String by hand?
Thanks.
All you need to do is set a collection in the query.
query.setParameterList("userIds", new Integer[] {1,2});
Then in your query
FROM User WHERE id IN (:userIds)
精彩评论