How can run a query like below with JPA. (It works with plain SQL)
SELECT t
FROM table t
WHERE
(
CASE WHEN (( ... subquery ... ) IS NULL)
THEN (t.category IS NULL)
ELSE (t.viewId = :viewId)
END
)
I get a MismatchedTokenException
at IS
THEN (t.category IS NULL)
Is it possible? Or need I to rewrite this query?
You can convert your where clause to something like:
where
((... my first condition ...) and (something is NULL))
or
(not (... first condition ...) and (something2 = otherthing))
I think you can't do that. Have a read of the JPQL grammar (here courtesy of OpenJPA). Here are the terms defining the case expression, specifically the general case expression you're using:
The expression on the right-hand side of the THEN
has to be a scalar_expression
. Which is to say:
I haven't rooted through the definition of all those terms, but i think they don't include things like (t.category IS NULL)
, i'm afraid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With