[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-892) HQL parser does not resolve alias in ORDER BY clause
Ben Wong (JIRA)
noreply at atlassian.com
Mon Jul 14 18:53:43 EDT 2008
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-892?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30660 ]
Ben Wong commented on HHH-892:
------------------------------
The workaround works only for simple query. For query such as:
select c.id,
c.customer,
(select count(s.totalSales) from sales s where s.customer = c and s.customerType = 4) as totalSales,
(select count(ex.totalExpense) from expenses ex where ex.customer = c and ex.customerType = 4) as totalExpenses
from customer c
order by totalSales / totalExpenses, c.id
The above is an example I made up, but that's what I am trying to do with my (more) complex HQL query. Unless I am wrong, I don't think you can stick subselect clauses in the order by.
P.S. I don't mean to whine, but how hard is it to replace the alias in the order by clause with the generated ones by Hibernate when generating the SQL from HQL? I would think this is a simple fix (or enhancement).
Ben
> HQL parser does not resolve alias in ORDER BY clause
> -----------------------------------------------------
>
> Key: HHH-892
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-892
> Project: Hibernate3
> Issue Type: Bug
> Components: query-hql
> Affects Versions: 3.0.5
> Environment: Hibernate 3.0.5, MySQL, Tomcat
> Reporter: Guido Laures
> Priority: Minor
>
> 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