I need to know how to call a SQL
function like HOUR()
in a @NamedQuery
in Java Persistence.
To make it simpler, In a table that has a starttime (TIMESTAMP
) column, I need to get the rows that have the startime falling between CURRENT_TIMESTAMP
and HOUR(CURRENT_TIMESTAMP)+1
. I have spent a day on Google and still did not manage to find a answer.
The following query works when tried with JAVADB
, however the same fails in @NamedQuery
.
Java DB Instance:
select e.EMPLOYEEID, e.FIRSTNAME, r.STARTTIME, r.ENDTIME from reservation r, employee e
where e.EMPLOYEEID = r.EMPLOYEEID AND HOUR(r.STARTTIME) = HOUR(CURRENT_TIMESTAMP)
@NamedQuery:
@NamedQuery(name="reservation.getcurrent",query = "select e.EMPLOYEEID, e.FIRSTNAME,
r.STARTTIME, r.ENDTIME from reservation r, employee e where e.EMPLOYEEID = r.EMPLOYEEID
AND HOUR(r.STARTTIME) = HOUR(CURRENT_TIMESTAMP)")
ERROR:
[2014-04-22T17:03:00.946+0530] [glassfish 4.0] [SEVERE] [] [javax.enterprise.system.core] [tid: _ThreadID=38 _ThreadName=admin-listener(5)] [timeMillis: 1398166380946] [levelValue: 1000] [[
Exception while deploying the app [LyndaPortalReservation] : Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Deployment of PersistenceUnit [LyndaPortalReservationPU] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [select e.EMPLOYEEID, e.FIRSTNAME, r.STARTTIME, r.ENDTIME from reservation r, employee e where e.EMPLOYEEID = r.EMPLOYEEID AND HOUR(r.STARTTIME) = HOUR(CURRENT_TIMESTAMP)].
[126, 169] The right expression is not a valid expression.]]