Java – JPA query with case when in the where clause How do you do it?

How to use JPA to run the query shown below (it applies to pure SQL)

SELECT t
FROM table t
WHERE
  (
    CASE WHEN (( ... subquery ... )  IS NULL)
    THEN (t.category IS NULL)
    ELSE (t.viewId = :viewId)
    END
  )

I encountered miscatchedtokenexception in is

Then (t.category is null)

Is it possible? Or do I need to rewrite this query?

Solution

You can convert the where clause to:

where
    ((... my first condition ...) and (something is NULL))
    or
    (not (... first condition ...) and (something2 = otherthing))
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>