-->
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.  [ 6 posts ] 
Author Message
 Post subject: Finding max in HQL
PostPosted: Fri Jun 10, 2005 2:22 am 
Newbie

Joined: Fri Jun 10, 2005 2:13 am
Posts: 1
I am developing an application with Hibernate2.1.4 and JBoss-3.2.7. I want to write a query for finding a max value of a particular column in a table. How can I give this? Can anyone give me an example.

I tried giving like the below:

"select max(Settlement.SettlementPK.SettlementId) from Settlement"

but it returns the all the data. I want only one row of data which has the max value. Any help.

Thanks.

bh_t_76


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 4:46 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Maybe leave out Settlement:
"select max(SettlementPK.SettlementId) from Settlement"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 10:26 am 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
Integer max = (Integer)HibernateUtil.getSession()
.createCriteria(YourClass.class)
.setProjection(Projections.max("property"))
.uniqueResult();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 10:29 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Nebob wrote:
Integer max = (Integer)HibernateUtil.getSession()
.createCriteria(YourClass.class)
.setProjection(Projections.max("property"))
.uniqueResult();


>>I am developing an application with Hibernate2.1.4

Quoted stuff only works with H3. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 10:30 am 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
Ah damn. I lose at the reading comprehension.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 10:44 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Quote:
Finding max in HQL


Also trying to use HQL not Criteria API ;-).


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