Query using “CASE WHEN” statement in WHERE causes QuerySyntaxException: unexpected AST

泄露秘密 提交于 2019-12-02 01:01:20

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!