I am writing a JPQL query which queries based on a Categories collection. My categories can be null and hence I am checking using :categories=NULL.
@Query("Select v from Vendor v join v.org vorg join v.categories cats WHERE vorg.email =:email AND (cats in :categories or :categories = NULL)")
Set<Vendor> filterVendors(@Param("emailId") String emailId, @Param("categories") Set<Category> categories);
The above works fine when categories is NULL. However, when categories is more than one value I get the error
java.sql.SQLException: Operand should contain 1 column(s)
And the hibernate relevant trace is
category6_.category_id in ( ? , ? ) or ( ? , ? ) is null )
How does one check for null on a collection in JPQL ? I think solving for that should resolve this error. Any help appreciated
Thanks.