JPQL Illegalargumentexception - Unexpected token: SUM

Asked

Viewed 146 times

0

java.lang.Illegalargumentexception: org.hibernate.hql.internal.Ast.Querysyntaxexception: Unexpected token: SUM near line 1, column 1 [SUM(e.quantidade) FROM br.com.pmro.coad.modelo.Stock and Join fetch e.products Prod GROUP BY id id]

//CONSULTATION 1 - WORKING

return this.em.createQuery("FROM Estoque e join fetch
e.produtos",Estoque.class).getResultList();

//CONSULTATION 2 - WORKING

return this.em.createQuery("FROM Estoque e join fetch e.produtos prod
GROUP BY prod.id",Estoque.class).getResultList();

//CONSULTATION 3 - GIVING DICK

return this.em.createQuery("SUM (e.quantidade) FROM Estoque e join fetch e.produtos prod GROUP BY prod.id",Estoque.class).getResultList();

1 answer

0

Is missing the select right at the beginning, as you want to return a single value that would be the sum and not the whole object.

"SELECT SUM (e.quantidade) FROM Stock and Join fetch e.produtos Prod GROUP BY Prod.id Return this.em.createQuery("SUM(e.quantidade) FROM Stock and Join fetch e.products Prod GROUP BY Prod.id",Stock.class). getResultList();

  • I would like to return the whole object and not just the sum.

  • How you used group by so put in SELECT Prod,SUM(e. quantity)

  • I managed to solve but in a very different way. Thank you for having given this help anyway.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.