How to skip @Param in @Query if is null or empty in Spring Data JPA
" and ds.statusCode in :paymentStatuses"
into
" and (:paymentStatuses is null or ds.statusCode in :paymentStatuses)"
Try changing
" and ds.statusCode in :paymentStatuses"
into
" and (COALESCE(:paymentStatuses, null) is null or ds.statusCode in :paymentStatuses)"
This solution will work for the empty list, null list, and a list with items 1 or more.