Java createNativeQuery: How to set parameter as an option?

321 views Asked by At

I have an use-case where passing parameters is optional. Can this be somehow achieved as if I try to set parameter (Using keyName or position) and if the key or position is absent in main query it returns IllegalParameterException.

This is useful if I have a dynamic query coming into method and want's to set some default values if possible.

Say:

Select ............ where date = :date

And if we have parameter value set for key "date" that will be used.

In other cases

Select .............. where date = NOW()

Here even though we have value set for key "date", we don't need to use

Any suggestion is welcome!

0

There are 0 answers