Hibernate HQL Query : How to set a Collection as a named parameter of a Query?

karlgrz picture karlgrz · Feb 20, 2009 · Viewed 100.5k times · Source

Given the following HQL Query:

FROM
    Foo
WHERE
    Id = :id AND
    Bar IN (:barList)

I set :id using the Query object's setInteger() method.

I would like to set :barList using a List of objects, but looking at the Hibernate documentation and list of methods I cannot see an obvious choice of which to use. Any ideas?

Answer

Jason Cohen picture Jason Cohen · Feb 20, 2009

Use Query.setParameterList(), Javadoc here.

There are four variants to pick from.