tags:

views:

29

answers:

1

Hello,

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.

+1  A: 

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)
Zoidberg
It works if a remove elements... thanks!
Rafael
Thats what I thought, it looked like you were pretty close... but I put in a full answer because I had an accept stolen from me earlier today.Good luck!
Zoidberg