0

This is my query.

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();

I'm getting below error.

java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Syntax error parsing the query [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], line 1, column 91: unexpected token [(]. Internal Exception: NoViableAltException(83!=[661:1: simpleConditionalExpressionRemainder[Object left] returns [Object node] : (n= comparisonExpression[left] | (n1= NOT )? n= conditionWithNotExpression[(n1!=null), left] | IS (n2= NOT )? n= isExpression[(n2!=null), left] );])

How can I solve this?

1 Answer 1

0

MONTH, YEAR, etc are not valid JPQL. See http://www.datanucleus.org/products/accessplatform_4_0/jpa/jpql.html#JPQL_BNF_Notation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.