-->
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: Max of all the Timestamps
PostPosted: Thu Jul 06, 2006 5:10 am 
Beginner
Beginner

Joined: Fri Jun 16, 2006 7:47 am
Posts: 27
Hi,

I have this requirement wherein I need to fetch the record with the maximum Timestamp from a table.

How do I do this in Hibernate?

Thanks
Any help would be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 5:21 am 
Beginner
Beginner

Joined: Fri Jun 16, 2006 7:47 am
Posts: 27
It may be something like this:

Criteria shipWindowCriteria = session.createCriteria(Employee.class)
.add(Expression.eq("EmpNumber",poNbr)
.add(Expression.eq("CustCd",custCd)

I need to add some Expression "TimeStamp" which would be the max of all the Timestamps available for that table.

Something of the sort of :

.add (Expression.eq("TimeStamp", MAX( of all the Timestamps));

Please help.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 4:55 pm 
Newbie

Joined: Wed Oct 12, 2005 11:17 am
Posts: 7
I'll try to help, although I'm not exactly clear what the intent is. I'm not sure if you want the Employee with the greatest Timestamp or the greatest Timestamp itself.

If you want the Employee record with the greatest timestamp then you can order the result set by timestamp in descending order and get the first record:

Code:
.addOrder(Order.desc("timestamp"))


Another option would be to have a sql subquery, although this would not be as portable.

Another option would be to use a projection to get the max, but since I don't have too much experience with this I won't comment further.

Hope this helps!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 6:29 pm 
Beginner
Beginner

Joined: Fri Jun 16, 2006 7:47 am
Posts: 27
Hi aphawkes,

Thanks for your suggestion.

However, it's giving,
The method addOrder(Order) is undefined for the type SimpleExpression


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 3:10 am 
Beginner
Beginner

Joined: Fri Jun 16, 2006 7:47 am
Posts: 27
Hi aphawkes,

Thanks a Lot!

It works.

Regards.


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.