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:

@NamedQueries(value = {
@NamedQuery(
name = "Foo.getBarList",
query = "select f from Foo f where (:barlist is null or f.barlist.id in (:barslist)) " )})


from this both post:

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

JPA where clause any

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

I guess the problem was the id in query so I remove and the error stop, just change this "select f from Foo f where (:barlist is null or f.barlist in (:barslist)) "

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>)
}