Stephane Malbequi (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMDY3Njc0ODdm...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16189?atlOrigin=eyJpIjoiMDY3Nj...
) HHH-16189 (
https://hibernate.atlassian.net/browse/HHH-16189?atlOrigin=eyJpIjoiMDY3Nj...
) Hibernate 6, wrong order by and group by generated with MappedSuperclass and Generics (
https://hibernate.atlassian.net/browse/HHH-16189?atlOrigin=eyJpIjoiMDY3Nj...
)
Issue Type: Bug Affects Versions: 6.1.7 Assignee: Unassigned Components: hibernate-core,
regression Created: 16/Feb/2023 08:52 AM Environment: JDK 19, MacOs, Postgresql 11 on Mac
and the latest on Docker
Hibernate 6.1.7 and 6.2.0.CR2 affected
Priority: Major Reporter: Stephane Malbequi (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Hi,
You can find the unit test here
https://github.com/smalbequi/hibernate-test-case-bug-orderby (
https://github.com/smalbequi/hibernate-test-case-bug-orderby )
For the query:
select
c.id,
c. name ,
t.code,
g.id,
sum (e.balance)
from Card e
inner join e.generation g
inner join g. type t
inner join t.client c
group by c.id, t.code, g.id
order by c. name , t.code, g.id
The generated SQL is:
select
t1_0.client_id,
c2_0. name ,
g1_0.type_code,
c1_0.generation_id,
sum (c1_0.balance)
from
Card c1_0
join
Generation g1_0
on g1_0.id=c1_0.generation_id
join
CardType t1_0
on t1_0.code=g1_0.type_code
join
Client c2_0
on c2_0.id=t1_0.client_id
group by
t1_0.client_id,
g1_0.type_code,
c1_0.generation_id
order by
c2_0. name ,
g1_0.type_code,
c1_0.generation_id
h2 accepts the query but Postgresql doesn’t and raises the following error:
[42803] ERROR: column "c2_0.name," must appear in the GROUP BY clause or be used
in an aggregate function Position : 31
The ‘group by’ should be:
group by c2_0.id, t1_0.code, g1_0.id
The ‘order by’ should be:
order by c2_0.name, t1_0.code, g1_0.id
With Hibernate 5 the generated SQL is just perfect:
select
client3_.id as col_0_0_,
client3_. name as col_1_0_,
cardtype2_.code as col_2_0_,
generation1_.id as col_3_0_,
sum (card0_.balance) as col_4_0_
from
Card card0_
inner join
Generation generation1_
on card0_.generation_id=generation1_.id
inner join
CardType cardtype2_
on generation1_.type_code=cardtype2_.code
inner join
Client client3_
on cardtype2_.client_id=client3_.id
group by
client3_.id ,
cardtype2_.code ,
generation1_.id
order by
client3_. name ,
cardtype2_.code,
generation1_.id
(
https://hibernate.atlassian.net/browse/HHH-16189#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16189#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100216- sha1:a0b8fe5 )