Is it possible to go through and check an empty list in JPA?

I have a query called JPQL that takes a parameter Listas a parameter. I use the parameter in the phrase IN:

...WHERE x.id IN :list

I would like to do something like the following, but the syntax does not seem to allow me:

...WHERE :list IS EMPTY OR x.id IN :list

None of them will:

...WHERE SIZE(:list) = 0 OR x.id IN :list

Am I trying to make impossible in a query named JPA 2.0? I know how to do this using the criteria API or using plain old JPQL strings.

+5
source share
1 answer

What you are trying to do in the query seems pointless. You are trying to limit the results of a query using the state of a parameter. But you do not compare this parameter with anything in your choice.

Think about this query (this doesn't make sense):

SELECT * FROM SOMETABLE WHERE :list IS EMPTY

, , , : :

:list : ...WHERE x.id IN :list

:list : (NO WHERE CLAUSE AT ALL)

-3

All Articles