-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL having aggregation mysql
PostPosted: Fri Feb 26, 2010 2:20 pm 
Newbie

Joined: Fri Feb 26, 2010 2:10 pm
Posts: 1
Hi all,

I'm having a problem with using an aggregation in the where clause for an HQL query. it's pretty simple, something like this:

Code:
from Job as job
group by job.type
having max(job.end_time)


Basically, I get the following error:

Code:
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: max near line 1, column 67 [ from com.hp.cast.hibernate.Job as job  group by job.name  having max(job.end_time) ]


Which is right at the "m" of "max"

I see the following documentation:

http://docs.jboss.org/hibernate/core/3. ... l-grouping

Actually mentions that MySQL is an example of a database that cannot use aggregates in the having clause, however, I can do that just fine on my database:

Code:
mysql> select name,end_time from job group by name having max(end_time);
...
367 rows in set (0.13 sec)


and, the mysql docs confirm that it can do this on anything newer than 3.23:

http://dev.mysql.com/doc/refman/4.1/en/select.html

Is there a reason this is restricted in hibernate when it works on current mysql versions?

Thanks!!


Top
 Profile  
 
 Post subject: Re: HQL having aggregation mysql
PostPosted: Fri Feb 26, 2010 5:23 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Shouldn't you compare max(job.end_time) with some value. Eg. having max(job.end_time) > foo. MySQL isn't very picky about such things as Hibernate (and other databases).


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