Group by on alias doesn't replace alias

Description

When you group by on an alias, Hibernate doesn't use the column alias in the group by statement. It is best explained with the following example

The resulting SQL

Notice how in the SQL the group by statement still uses the "usr" alias defined in the HQL in stead of col_0_0_.

Environment

MySQL 5.x

Activity

Show:
Jan-Willem Gmelig Meyling
September 4, 2019, 3:06 AM

I've provided an implementation for this with https://github.com/hibernate/hibernate-orm/pull/3022

Jan-Willem Gmelig Meyling
July 17, 2019, 3:00 PM

I think this would be a nice addition for dialects that do support it. I just stumbled upon a use case where I want to group by a function that takes a parameter, and when the same fragment is reused in the group by clause (the usual workaround) it is not detected as the same fragment and the query will fail. Is there any way we could support this, even though it would be against the spec? Possibily enabled through a config property?

Brett Meyer
April 22, 2015, 9:14 PM

Closing rejected issues.

Gail Badner
July 25, 2014, 6:04 PM

Some DBs support it, but it is not ANSI SQL.

Marc Schipperheyn
July 25, 2014, 2:42 PM

Ok, strange. In straight SQL it works fine.

Fixed

Assignee

Jan-Willem Gmelig Meyling

Reporter

Marc Schipperheyn

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major