这是我的疑问。
List exp = entityManager.getEntityManager()
.createQuery("select sum(u.expenseAmount), u.wdExpenseGroup.expenseGroupName from WdExpense u WHERE MONTH(CAST(u.expenseDate as date)) = MONTH(NOW()) AND YEAR(CAST(u.expenseDate as date)) = YEAR(NOW()) group by u.wdExpenseGroup.expenseGroupId")
.getResultList();
我遇到了错误。
java.lang.IllegalArgumentException:发生异常时 在EntityManager中创建查询:异常描述:语法 解析查询时出错[select sum(u.expenseAmount), 来自WdExpense的u.wdExpenseGroup.expenseGroupName你好 MONTH(CAST(u.expenseDate as date))= MONTH(NOW())AND YEAR(CAST(u.expenseDate as date))= YEAR(NOW())group by u.wdExpenseGroup.expenseGroupId],第1行,第91列:意外令牌 [(]。内部异常:NoViableAltException(83!= [661:1: simpleConditionalExpressionRemainder [Object left]返回[Object node] :( n = comparisonExpression [left] |(n1 = NOT)?n = conditionWithNotExpression [(n1!= null),left] | IS(n2 = NOT)? N = isExpression [(n2!= null),left]);])
我该如何解决这个问题?
答案 0 :(得分:0)
MONTH,YEAR等不是有效的JPQL。 见http://www.datanucleus.org/products/accessplatform_4_0/jpa/jpql.html#JPQL_BNF_Notation