Java Question

hibernate where clause any with collection as a named parameter query

I'm wondering if is possible to make this kind of evaluation with collections like the query isn't working in my project at a class named query as follow:

FROM Foo WHERE Id = :id AND (:barlist is null or Bar in (:barlist))


from this both post:

JPA where clause any

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

Answer

instead of in HQL you can check

if(barlist==null){
    //query=FROM Foo WHERE Id = :id
}else{
   //query=FROM Foo WHERE Id = :id AND Bar in :barlist
   // query.setParameterList(:barlist",<list object>)
}
Comments