-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: problem with HQL alias
PostPosted: Wed Dec 28, 2005 11:56 pm 
Newbie

Joined: Tue Nov 22, 2005 12:48 am
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Dear all,

Hibernate version: 3.0.5

Name and version of the database you are using: Mysql 4.1

I'd like to issue the below HQL with the result order by the second column,

select ds.dataSourceId as id , count(distinct doc.author) as authorcount
from TbDataSource ds left join ds.tbDocuments doc group by ds order by authorcount desc

However, the HQL is convert to the below SQL:

select tbdatasour0_.data_source_id as col_0_0_, count(distinct tbdocument1_.author) as col_1_0_ from tb_data_source tbdatasour0_ left outer join tb_document tbdocument1_ on tbdatasour0_.data_source_id=tbdocument1_.data_source_id group by tbdatasour0_.data_source_id order by authorcount desc

The problem is the alias "authorcount" I defined is changed to "col_1_0_" by Hibernate which cause "Unknown column 'authorcount' in 'order clause'" error. How can I solve this problem? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 29, 2005 12:03 am 
Beginner
Beginner

Joined: Tue Dec 21, 2004 5:34 pm
Posts: 25
I know in most databases you cannot do that in SQL. You cannot use the alias in the order by clause. Have you tried this?

Code:
select ds.dataSourceId as id , count(distinct doc.author) as authorcount
from TbDataSource ds left join ds.tbDocuments doc group by ds order by count(distinct doc.author) desc


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 29, 2005 12:43 am 
Newbie

Joined: Tue Nov 22, 2005 12:48 am
Posts: 8
no ... mysql do not allow group function in order by cause.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.