-->
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: Usage of aggregate function with HQL
PostPosted: Wed Jan 24, 2007 10:03 am 
Newbie

Joined: Thu Aug 10, 2006 7:43 am
Posts: 14
I am working with Hibernate 3.1.3 and I wonder how I can tell Hibernate to give me a result for the following question:

A table has some columns (of course) and one of them is called modified and another is called dataId.
Each time a data is modified this will be protocolized in this table. Thus, it is possible that we have n entries for a dataId x.

I want to get the complete row from the DB/Hibernate specifying the dataId and using max(modified).

How is the syntax? I don't get it work.

I tried something like the following:

Code:
List result = getHibernateTemplate().find("from MyData where data = " + dataId + " having max(modified)");


Thank you,
Dirk


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 10:36 am 
Beginner
Beginner

Joined: Thu Sep 22, 2005 10:48 am
Posts: 30
Location: Rio de Janeiro, Brazil
SQL Having is apply with group by

Use a subquery to searsh max modified

Code:
from MyData md where md.data = " + dataId + " and md.modified =
( select max( mdt.modified ) from MyData mdt where md.data = mdt.data )

_________________
Please don't forget to rateME!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 11:01 am 
Newbie

Joined: Thu Aug 10, 2006 7:43 am
Posts: 14
passos wrote:
SQL Having is apply with group by

Use a subquery to searsh max modified

Code:
from MyData md where md.data = " + dataId + " and md.modified =
( select max( mdt.modified ) from MyData mdt where md.data = mdt.data )


Great! It works very well.
Thanky you.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.