2

I am using 2.4.1 eclipse link and oracle. This document lists several operator, which can be used while writing queries. There is one example as well. I want to use dateDifference function. Where can I find the details of the parameters to be passed while using these operator. Some example code will be great.

James
  • 17,965
  • 11
  • 91
  • 146
phoneynk
  • 110
  • 7

1 Answers1

1

The best source for the API is in the Expression class

http://www.eclipse.org/eclipselink/api/2.5/org/eclipse/persistence/expressions/Expression.html#dateDifference%28java.lang.String,%20java.util.Date%29

i.e.

SELECT e FROM Employee e WHERE OPERATOR('DateDifference ', e.startDate, 'year', e.endDate) > 10

You could also use the SQL() operation.

James
  • 17,965
  • 11
  • 91
  • 146
  • 1
    Thanks @James, for your help here. I have all ready marked your answer as accepted. The space in 'DateDifference ' is really tricky, I might never have thought of that. But looks like DateDifference requires support from DB, and is not supported by Oracle. The error being `java.sql.SQLSyntaxErrorException: ORA-00904: "DATEDIFFERENCE": invalid identifier`. Am I correct in my assumptions or is there something which can be done to use this with Oracle. – phoneynk Jun 05 '13 at 05:24
  • I would use the SQL standard EXTRACT function. EclipseLink supports this function in JPQL directly. – James Jun 05 '13 at 13:49