-->
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.  [ 5 posts ] 
Author Message
 Post subject: MySQL "group by" error
PostPosted: Wed Sep 10, 2003 2:15 pm 
Newbie

Joined: Wed Sep 10, 2003 2:11 pm
Posts: 3
Location: Romania
I have the following HQL query:

select entry.host, count(entry.id) from AccessLogEntry entry
group by entry.host order by count(entry.id) desc

On mysql, it fails with a generic error, and a message from server: "Invalid use of group function".
If I remove the order by clause, the query works fine. I suspect this is related to the fact that MySQL won't accept an aggregate function as an order criteria.

I'd like to do:

select entry.host, count(entry.id) as hits from ..

but, as far as I can tell, HQL won't allow me to (re)name the selected items.

Meanwhile, I'm running without the ordering, and order the resulted list in Java, but I'd rather have the query do it.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 05, 2003 3:35 pm 
Newbie

Joined: Wed Sep 10, 2003 2:11 pm
Posts: 3
Location: Romania
Any ideas? Is there any workaround?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 2:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
My SQL does not support aggregate functions in the order by clause, I think I recall.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 12:59 am 
Newbie

Joined: Wed Sep 10, 2003 2:11 pm
Posts: 3
Location: Romania
Thank you very much for your reply!

Can you suggest a workaround?
Is it possible to name a select entry? (select max(entry.id) AS mx ?)
Is there anything I can do, Java-side?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 4:49 pm 
Newbie

Joined: Wed Sep 17, 2003 3:49 am
Posts: 2
gabrielm wrote:
Thank you very much for your reply!

Can you suggest a workaround?
Is it possible to name a select entry? (select max(entry.id) AS mx ?)
Is there anything I can do, Java-side?


i have the same problem.
in order by class i am using column number instead of it alias
cause hibernate doesn't work with colum aliases


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