| I'm also having an issue with column aliases, specifically for a "group by" with a bind variable. My query is more complicated, but a small native example would be:
select someCol / ?, count(id) as ct from someTable group by someCol / ?
Even though I always expect both bind variables to be the same, the above query doesn't work because different values could technically be bound. This means an SQL error might be:
If the bind variables are replaced with the hardcoded value exactly, there is no problem. For context, I'm using QueryDSL. Another way to fix this is to group by the alias. E.g.
select someCol / ? as someAlias, count(id) as ct from someTable group by someAlias
So that is what I am trying to do, but there seems to be an issue in Hibernate. When the org.hibernate.hql.internal.ast.tree.SelectClause is constructed, it does in fact include the aliases such as "someAlias" in the aliases member variable. But when org.hibernate.hql.internal.antlr.SqlGeneratorBase invokes selectColumn(), it says sc = (AST)t;, so the alias is set to e.g. "col_1_0" instead of "someAlias", even though the alias is available to it. |