I am working on Eclipselink named query and have issues in setting optional parameter for timestamp.
My requirement is to query data with timestamp if the field is entered by the user. As the field is optional, I am checking for ''0000-00-00 00:00:00' or the user input date. The query snippet is as follows. However it doesn't work.
DataConstants.java
==================
public static String DATE_CHECKING_FORMAT = "0000-00-00 00:00:00"
Named Query
===========
entityManager.createNamedQuery("Requests.SearchAllData")
.setParameter("fromTime", ((selectionCriteria.getFromRequestTime() == null)? DataConstants.DATE_CHECKING_FORMAT : selectionCriteria.getFromRequestTime()))
.setFirstResult(offset).setMaxResults(limit).getResultList();
@NamedQuery(name = "Requests.SearchAllData",
query = "select ws.requestTimeStamp from StudentBE ws where ((:fromTime = to_timestamp('0000-00-00 00:00:00','dd-mm-yyyy hh24:mi:ss')) or (ws.requestTimeStamp >= :fromTime))),
While executing, I am getting this error.
Exception Description: Syntax error parsing the query [Requests.SearchAllData: select ws.requestTimeStamp from StudentBE ws where ((:fromTime = to_timestamp('0000-00-00 00:00:00','dd-mm-yyyy hh24:mi:ss')) or (ws.requestTimeStamp >= :fromTime)), line 1, column 63: syntax error at [=]. Internal Exception: MismatchedTokenException(82!=84)
Please suggest how to use optional timestamp field.
Thanks!!!