The criteria API does not have a provision to add another query as a restriction.. i think what @Niroshan Abayakoon was trying to say is that you need to execute the queries for the IN
clause seperatly & add the result to the Restrictions.in()
condition.
List<?> entity2Data=//get data from either a query or criteria
List<?> entity3Data=//get data from either a query or criteria
Criteria c = // obtain criteria from session
// basically creates an OR condition chain
Disjunction orConditions = Restrctions.disjunction();
orConditions.add(Restrictions.in("obj", entity2Data));
orConditions.add(Restrictions.in("obj", entity3Data));
c.add(orConditions);
this would get hibernate to consider the list within the IN
clause.
Its always better to fallback to HQL in situations like this.