开发者

Hibernate HQL is failing on alias ordering

I have this query in hql:

select sum(settledPricePerDownloadExpense),avg(settledPricePerDownloadExpense),sum(siteIdCount) as ct,sum(settledPricePerDownloadExpense) 
from PpdCampaignReporting  where id.ppdCampaignReportDate between 'Wed May 11 00:00:00 EDT 2011' and 'Thu May 12 23:59:59 EDT 2011' And id.ppdCampaignActionTypeId in (1, 2, 3) And id.ppdCampaign.ppdCampaignId in (62,63,82,83,84,95,97) 
group by id.ppdCampaignActionTypeId,id.siteId order by ct

The error I am getting back is this:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'ct'.

Which I don't understand since I 开发者_JAVA技巧have sum(siteIdCount) as ct


Ordering by alias defined in select clause is a known bug in Hibernate. It was fixed in 3.6.x branch, so make sure you're using the latest production release.

Be aware, though, that there have been incompatible changes made with regards to 3.5 and earlier versions (dealing with user types and lobs are the two major areas) so you need to be careful when upgrading.

Alternatively, you can either use "order by 1" (if your RDBMS supports it; I'm not sure about SQL Server) or order by expression (e.g. order by sum(siteIdCount) in your case).

P.S. Group by alias is still broken.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜