Hi,
I have a number of jpa queries with order by and group by clauses which share the same columns. In 3.3.2, the order by expressions are converted to use the left join aliases, but the groupBy clause continues to use the foreign key column in the generated query. This causes a failure in Oracle "ORA-00979 not a GROUP BY expression" because the order by has columns not in the group by.
Here's a pared down example to illustrate the issue.
JPAQuery query = new JPAQuery(entityManager)
.from(user)
.groupBy(user.department().id)
.orderBy(user.department().id.asc());
return query.list(user.count(), user.department().id);
In 3.3.2, the generated query is:
select count(user0_.id) as col_0_0_, user0_.department_id as col_1_0_
from users user0_
left outer join department department1_ on user0_.department_id=department1_.id
group by user0_.department_id
order by department1_.id asc;
ORA-00979: not a GROUP BY expression occurs because the order by uses columns not in the group by. If I remove the order by, the query works fine. If I change the query to the 3.2.4 behavior, it also works:
select count(user0_.id) as col_0_0_, user0_.department_id as col_1_0_
from users user0_
group by user0_.department_id
order by user0_.department_id asc;
Does anyone know of a way to work around this in 3.3.2 (aside from rewriting all the queries to add explicit left joins)? Would it be possible to add an option to disable the new behavior?
Thanks,
David