I\'m trying to make a query using Spring Data, but I cannot make it work:
@Query(SELECT t FROM Thing t WHERE name LIKE :name AND CASE WHEN (:minVal <= 0)
It looks like Hibernate cannot evaluate the result of a CASE expression when it returns a boolean literal directly. A workaround is to make the CASE expression part of another expression, e.g. by comparing it to another boolean literal.
So instead of:
... AND CASE WHEN (:minVal <= 0) THEN TRUE ELSE (val <= :minVal) END
Try:
... AND (CASE WHEN (:minVal <= 0) THEN TRUE ELSE (val <= :minVal) END) = TRUE
But looking at that expression, wouldn't it be simpler to just do:
... AND (:minVal <= 0 OR val <= :minVal)
Is it not equivalent?