0

I am trying to retrieve all the entity from the TransactionE t entity where the month of t.purchasedDate is equal to the current month.

However, I encountered a syntax error when my code run.

String query = "SELECT t FROM TransactionE t WHERE Month(t.purchaseDate) = Month(" + getCurrentDate()+")";

Query q = em.createQuery(query);

Any help please?

getCurrentDate() is a function that will return the date of current day in "yyyy-MM-dd" format.

The below is a query that I was hoping to achieve. SELECT t FROM TransactionE t WHERE Month(t.purchaseDate) = Month("2013-10-06")

Error : Caused by: Exception [EclipseLink-8025] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.JPQLException Exception Description: Syntax error parsing the query [SELECT t FROM TransactionE t WHERE Month(t.purchaseDate) = Month(getCurrentDate()), line 1, column 40: unexpected token [(].

Lawrence Wong
  • 1,129
  • 4
  • 24
  • 40

1 Answers1

0

Month not is a standard JPQL function. Try:

SELECT t 
  FROM TransactionE t 
 WHERE FUNC('MONTH', t.purchaseDate) = FUNC('MONTH', CURRENT_DATE)
Paul Vargas
  • 41,222
  • 15
  • 102
  • 148
  • Hi. I tried and I got this error. Syntax error parsing the query [SELECT t FROM TransactionE t WHERE FUNC('MONTH', t.purchaseDate) = FUNC('MONTH', 2013-10-10)] – Lawrence Wong Oct 09 '13 at 16:37