[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-892) HQL parser does not resolve alias in ORDER BY clause
Chris Wilson (JIRA)
noreply at atlassian.com
Thu Nov 19 04:32:10 EST 2009
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-892?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Chris Wilson updated HHH-892:
-----------------------------
Attachment: HibernateHavingAliasTest.java
This is also a problem for HAVING columns. See the attached test case for a very simple example, which generates the following query on MySQL:
select house0_.id as col_0_0_,
SUM(case cats1_.sex when 'M' then 1 else 0 end) as col_1_0_,
SUM(case cats1_.sex when 'F' then 1 else 0 end) as col_2_0_
from House house0_
inner join Cat cats1_ on house0_.id=cats1_.house_id
group by house0_.id
having num_male<>num_female;
generating the same error message:
WARN JDBCExceptionReporter: SQL Error: 1054, SQLState: 42S22
ERROR JDBCExceptionReporter: Unknown column 'num_male' in 'having clause'
In my view, using the Hibernate generated aliases (col_1_0_ and col_2_0_) in the having clause is not a very good workaround, because they are not specified by the standard and could change at any time.
Since I provided an explicit alias name, I would like it to be used in the SQL query, but failing that, I hope it would be possible to resolve aliases in the HAVING clause.
> HQL parser does not resolve alias in ORDER BY clause
> -----------------------------------------------------
>
> Key: HHH-892
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-892
> Project: Hibernate Core
> Issue Type: Bug
> Components: query-hql
> Affects Versions: 3.0.5
> Environment: Hibernate 3.0.5, MySQL, Tomcat
> Reporter: Guido Laures
> Priority: Minor
> Attachments: HibernateHavingAliasTest.java
>
>
> When using an alias for an ORDER BY clause this is not always correctly resolved. Example:
> SELECT SUM(A.x) AS mySum FROM MyClass AS A GROUP BY A.y ORDER BY mySum
> does not work because "mySum" is not resolved in the ORDER BY clause which results in an exception telling that mySum is an unknown column.
> Workaround (not to say "hack") is using:
> SELECT SUM(A.x) AS mySum FROM MyClass AS A GROUP BY A.y ORDER BY col_0_0_
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list