-->
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: fastest way to return the last record in a table in mysql
PostPosted: Sun Dec 09, 2007 3:34 am 
Newbie

Joined: Wed Sep 05, 2007 9:26 am
Posts: 16
Hi,
I need to get the latest record added to a table, is the following the best practice? thanks.

Angelo

List<App> lst = session.createQuery("from App order by txdate desc").list();
if (lst.size() > 0)
return lst.get(0);
else
return null;


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 09, 2007 12:47 pm 
Newbie

Joined: Fri Dec 07, 2007 5:52 am
Posts: 4
Location: Budapest, Hungary, EU
I would add setMaxResults:
Code:
List<App> lst = session.createQuery("from App order by txdate desc").setMaxResults(1).list();
if (lst.size() > 0)
  return lst.get(0);

return null;


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.