GroupBy After Chained InnerJoins Produced invalid Postgres SQL after upgrading to Hibernate6

After upgrading to Hibernate6 we get for the following type of querys an SQL Exception on Postgres:

HQL:

select distinct flightEvent.originDestAirport.country
                flightEvent.originDestAirport
from FlightEvent flightEvent
         inner join flightEvent.originDestAirport.country as CountryBreakdown1
         inner join flightEvent.originDestAirport as OrgDestBreakdown1
group by flightEvent.originDestAirport.country.id, flightEvent.originDestAirport.country.name,
         flightEvent.originDestAirport.country.isoCountryCode, CountryBreakdown1.id, flightEvent.originDestAirport.id,
         flightEvent.originDestAirport.name, flightEvent.originDestAirport.iataCode,
         flightEvent.originDestAirport.icaoCode, OrgDestBreakdown1.id

SQL:

select distinct c2_0.id,
                c2_0.iso_country_code,
                c2_0.name,
                oda2_0.id,
                oda2_0.city_name,
                oda2_0.country_id,
                oda2_0.iata_code,
                oda2_0.icao_code,
                oda2_0.latitude,
                oda2_0.longitude,
                oda2_0.name
from flight_event fe1_0
         join airport oda1_0 on oda1_0.id = fe1_0.origin_dest_airport_id
         join country c1_0 on c1_0.id = oda1_0.country_id
         join airport oda2_0 on oda2_0.id = fe1_0.origin_dest_airport_id
         join country c2_0 on c2_0.id = oda2_0.country_id
group by oda2_0.country_id, c2_0.name, c2_0.iso_country_code, c1_0.id, oda2_0.id, oda2_0.name, oda2_0.iata_code,
         oda2_0.icao_code, oda2_0.id;

Error:

ERROR: column "c2_0.id" must appear in the GROUP BY clause or be used in an aggregate function

Additional Information:

  • Postgres Database: 14.12
  • ‘org.postgresql:postgresql:42.7.3’,
  • ‘org.hibernate.orm:hibernate-core:6.5.2.Final’
  • Does not fail if run against a h2 testdatabase

Is this a well known bug?
Are there ways to prevent hibernate from producing such an invalid query?
Is that the same error as Hibernate 6 / Wrong order by and group by generated with MappedSuperclass and Generics ?

Please try 6.6.0.CR1. This might have already been solved. If you still encounter that problem, please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.