I get List by executing a query. This must be passed to another query of IN clause values. How to pass them in HQL?
我通过执行查询得到List 。这必须传递给IN子句值的另一个查询。如何在HQL中传递它们?
We can convert List to Array and can pass it, that's not a problem.
我们可以将List转换为Array并且可以传递它,这不是问题。
Finally, I must pass the list in List or Array or String form to the IN clause.
最后,我必须将List 或Array或String形式的列表传递给IN子句。
2 个解决方案
#1
71
from AUTOS a where a.model in (select m.model from MODELS m)or
要么
Query query1 = session.createQuery("select s.id from Salary s where s.salary 49980");Query query2 = session.createQuery("from Employee e where e.id in (:ids)").setParameterList("ids", query1.list());query2.list();#2
3
I know it's been a while and you have been trying to pass the value of a different query as a queryParameter, you can also pass set or collections to in clause in HQL with 'elements()' - here's a simple example of such usage: Hibernate query: does a Set contains a certain Object?
我知道已经有一段时间了,你一直试图将不同查询的值作为queryParameter传递,你也可以使用'elements()'将集合或集合传递给HQL中的in子句 - 这是一个这样用法的简单示例: Hibernate查询:Set是否包含某个Object?