Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable the rewrite of the order by expressions under certain conditions #732

Closed
dzeigler opened this issue May 3, 2014 · 1 comment
Closed
Labels
bug
Milestone

Comments

@dzeigler
Copy link

@dzeigler dzeigler commented May 3, 2014

This issue is related to the google groups discussion here: https://groups.google.com/forum/#!topic/querydsl/9GMQp5FZ5Lk

Timo suggests disabling the rewrite of the order by expressions under certain conditions. Having the same expressions in other parts of the query could be a good start.

Original description of the problem:
I recently upgraded to 3.3.2 from 3.2.4 and I believe we're running into an issue related to this change in 3.3.0: #582
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;
@timowest timowest added this to the 3.3.4 milestone May 4, 2014
@timowest timowest added the fixed label May 8, 2014
@timowest timowest modified the milestone: 3.3.4 May 10, 2014
@timowest timowest added the bug label May 10, 2014
@timowest
Copy link
Member

@timowest timowest commented May 20, 2014

Released in 3.3.4

@timowest timowest closed this May 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.