1

I use Hibernate as persistence provider, database is Oracle XE. Here is a JP QL query:

SELECT news, COUNT(comments) 
  FROM News news JOIN news.comments comments 
GROUP BY news

News is in one-to-many relation with Comments.

When i try to use it, the following error appears:

ERROR SqlExceptionHelper:146 - ORA-00979: not a GROUP BY expression

But in Pro JPA 2, 2nd edition (page 222) I found almost the same query:

SELECT e, COUNT(p)
FROM Employee e JOIN e.phones p
GROUP BY e

What's wrong with the former one?

Aliaxander
  • 2,547
  • 4
  • 20
  • 45
  • Perhaps `employee.e` is a valid field. – Gordon Linoff May 10 '15 at 21:20
  • But `e` is an identification variable for `Employee`. – Aliaxander May 10 '15 at 21:27
  • 1
    I'm just pointing out that Oracle would not complain about that query if `e` were also a column in the table. – Gordon Linoff May 11 '15 at 00:57
  • Try to add the sql query that generates Hibernate for this query to see where is the problem. Perhaps it is case sensitive issue on the identification variables. For print out the queries you can set the Hibernate's property show_sql to true (ser in the persistent.xml) – Guillermo May 11 '15 at 05:47
  • It's not good to have a column "news" with the same name as the table "news". – Ollie May 21 '15 at 14:01

0 Answers0