7
@Query(value = "Select f from Documents f " + "RIGHT JOIN f.documentStatus ds " + "where f.billingAccount.accountId in :billingAccountIdList " + " and ds.statusCode in :paymentStatuses" + " and f.paymentDate < :paymentDate") List<FinancialDocumentEntity> getFinancialDocumentsOverdue(@Param("billingAccountIdList")List<String> billingAccountIdList, @Param("paymentStatuses") List<String> paymentStatuses, @Param("paymentDate") Date paymentDate); 

I have query like above. It is possible to skip searching param for example @Param("paymentStatuses") in query method if is null or is empty ?

1

2 Answers 2

16

Try changing

" and ds.statusCode in :paymentStatuses" 

into

" and (:paymentStatuses is null or ds.statusCode in :paymentStatuses)" 
Sign up to request clarification or add additional context in comments.

6 Comments

How it should be if the parameter should be checked as a member? I tried this but not works: Select a from MyEntity a where (:groups is null or :groups member of a.groups)
same for me.. if i use parameter name twice . it does not works
Try this: " and (:#{#paymentStatuses == null} or ds.statusCode in :paymentStatuses)"
This solution will fail if list has more than one item
Can you please explain what we can do for mongo DB for this specific case ?
|
6

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.

2 Comments

Thanks I solved this oracle.jdbc.OracleDatabaseException: ORA-00920: invalid relational operator error
for list input is this the correct solution, thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.