I am trying to cover the case where the :creationDateTime is Null to get the same result as the following query “SELECT o FROM ExtraNetOrder o”. I searched it on the internet and found the solution by adding IS NULL
, but it
does not work in my case. Currently I am getting the following error:
Caused by: java.lang.IllegalStateException: Query argument creationDateTime not found in the list of parameters provided during query execution.
If the paramter :creationDateTime does not exist, then the query should be executed without the where parameter clause. In my table, I don’t have creationDateTime with the NULL value.
In the final query I have 3 paramter which I am passing to the query. for the simplicity I added just one paramter (creationDateTime).
I am using EclipseLink in the projekt.
@NamedQueries({ @NamedQuery(name="order_by_filter_options", query="SELECT o FROM ExtraNetOrder o " + " WHERE :creationDateTime IS NULL OR :creationDateTime = '' OR o.creationDateTime >=:creationDateTime ") }) ------------------- Query q = em.createNamedQuery("order_by_filter_options"); if (fromDate != null) q.setParameter("creationDateTime", fromDate); @SuppressWarnings("unchecked") List<ExtraNetOrder> orders = q.getResultList();
Advertisement
Answer
You need to set :creationDateTime to null if the fromDate is null. Just remove the if
and always call q.setParameter("creationDateTime", fromDate);