JPA autodetect argument type
Doing a query like this:
Query query = entityManager.createQuery("FROM Employee e WHERE :type IS NULL OR e.empoyeeType = :type");
query.setParameter("type", employeeType); // employeeType is an ENUM
This results in hibernate not being able to determine the type of the parameter and uses VARBINARY. This results in empty resultsets if employeeType != null. Setting the parameter as employeeType.name() does give the expected resultset.
Changing the query to this:
Query query = entityManager.createQuery("FROM Employee e WHERE e.empoyeeType = :type OR :type IS NULL");
query.setParameter("type", employeeType); // employeeType is an ENUM
In this case hibernate is able to determine the type and passes the parameter as type ENUM.
Conclusion: it is important to keep in mind that hibernate needs to be able to determine the parameter type and needs some help with that.