Reputation: 163
I have the follow @Query in my repository :
@Query(value = "SELECT * FROM tableA a WHERE a.id IN :listId ",
nativeQuery = true)
public Page<ObjectA> findInById(@Param(listId) List<String> listId);
And I would like to select all elements if listId
is empty or null.
How can I do that? If possible I'd like to keep the @Query
.
Upvotes: 1
Views: 824
Reputation: 1280
Just add an or condition, like
@Query(value = "SELECT * FROM tableA a
WHERE (a.id IN :listId or coalesce(:listId , null) is null)",
nativeQuery = true)
public Page<ObjectA> findInById(@Param(listId) List<String> listId);
Upvotes: 2