Hibernate HQL 查询:如何将集合设置为查询的命名参数?

Hibernate HQL 查询:如何将集合设置为查询的命名参数?

问题描述:

鉴于以下 HQL 查询:

Given the following HQL Query:

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

我使用 Query 对象的 setInteger() 方法设置了 :id.

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

我想使用对象的 List 设置 :barList,但是查看 Hibernate 文档和方法列表我看不到要使用的明显选择.有什么想法吗?

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?

Use Query.setParameterList(), Javadoc 在这里.

有四种变体可供选择.