简体   繁体   English

EJB QL数据语法错误

[英]EJB QL data Syntax error

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. 我正在尝试从TransactionE t实体检索所有实体,其中t.purchasedDate的月份等于当前月份。

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. getCurrentDate()是一个将以“ yyyy-MM-dd”格式返回当前日期的函数。

The below is a query that I was hoping to achieve. 以下是我希望实现的查询。 SELECT t FROM TransactionE t WHERE Month(t.purchaseDate) = Month("2013-10-06") 从事务中选择t t月份(t.purchaseDate)=月份(“ 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 [(]. 错误:由以下原因引起:异常[EclipseLink-8025](Eclipse Persistence Services-2.3.2.v20111125-r10461):org.eclipse.persistence.exceptions.JPQLException异常描述:语法错误解析查询[SELECT t FROM TransactionE t WHERE Month (t.purchaseDate)= Month(getCurrentDate()),第1行,第40列:意外令牌[[]。

Month not is a standard JPQL function. Month不是标准的JPQL函数。 Try: 尝试:

SELECT t 
  FROM TransactionE t 
 WHERE FUNC('MONTH', t.purchaseDate) = FUNC('MONTH', CURRENT_DATE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM