I'm trying to write a query in which I need to check whether the collection passed as a parameter empty or not.
I'm writing something like this:
@Query("SELECT u FROM User u" +
"WHERE" +
" :ids IS EMPTY" +
" OR u.id IN :ids")
Collection<User> findUsers(@Param("ids") Collection<String> ids);
This code fails on startup with QuerySyntaxException: ??? is not mapped
. The stack-trace doesn't give any valuable information, but I found out that if I remove the next part:
:ids IS EMPTY
it starts working.
Q: How to use IS EMPTY
for query parameters? Or how to check that collection is empty in any other way?
Note:
- I'm using Spring Boot 1.5.8.RELEASE.
- I also looked on "Passing empty list as parameter to JPA query throws error" which is different and didn't help.
- The code I posted is primitive, it was added just for illustration purpose, my real query is quite complex and I really need to check collection emptiness.