Question

I'm trying to 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.

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top