-->
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.  [ 4 posts ] 
Author Message
 Post subject: Ordering by Aggregate function: revisited
PostPosted: Fri Feb 20, 2004 11:12 am 
Newbie

Joined: Tue Feb 03, 2004 5:49 pm
Posts: 2
Hi, I know this topic has been discussed to death but I see no viable solution and the only semi-work-around I see have no real explanation so I was hoping somebody would enlighten me with the answer. Thanks.

The HQL I need to run is,
"select u.name, count(*) ct from user u group by u.name order by ct desc"

After searching through this forum, now I realize HQL does not allow aliases on the selected columns. So the only possible method to achieve the desired result would be to use the "column number" as somebody proposed. ( eg] ORDER BY col#2)

Now the question is, how do I indicate the column number in HQL? Is it even possible? If not, is there a work-around for this problem?

Yes I'm using MySQL and I understand MySQL's bug is preventing me to have aggregate function in the ORDER BY. But at least MySQL has a work-around to use the aliase. Is there an equivalent in Hibernate?

I'm losing sleep over this matter... please help.
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 12:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, HQL does not have aliases. Why not just fall back to a native SQL query?


Top
 Profile  
 
 Post subject: re
PostPosted: Fri Feb 20, 2004 12:47 pm 
Newbie

Joined: Tue Feb 03, 2004 5:49 pm
Posts: 2
I thought you had to have a persistent object to fall back to native SQL.
So in this case do I need to create an object with the property (String name) and (int count) to get the result?

If this is true, then I guess I misunderstood the logic. I thought there always has to exist a database table for each persistent object.

Is this a fairly safe assumption? (I can't test out the code until tonight so I'm trying to get as much information as possible before getting at this again. Thanks.)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 12:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Oh, I mean, fall back to direct JDBC. Easy.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.