passing list to IN clause in HQL or SQL?

Mr.Chowdary picture Mr.Chowdary · Sep 29, 2012 · Viewed 94.8k times · Source

I get List<Strings> by executing a query. This must be passed to another query of IN clause values. How to pass them in HQL?

We can convert List to Array and can pass it, that's not a problem.

Finally, I must pass the list in List<String> or Array or String form to the IN clause.

Answer

Sergii Shevchyk picture Sergii Shevchyk · Oct 1, 2012
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 < 50000 AND s.salary > 49980");
Query query2 = session.createQuery("from Employee e where e.id in (:ids)").setParameterList("ids", query1.list());
query2.list();