-->
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: fast way to get the first record
PostPosted: Sun Aug 10, 2008 9:49 am 
Newbie

Joined: Mon Jul 21, 2008 5:40 am
Posts: 16
Hi Gurus,

I have a table as follow, what is the fastest way to get the first record in the table(in the order of pK)? thanks.

@Entity
@Table(name = "config_id")
public class ConfigID {
private Long id;
@Id @GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 11, 2008 6:45 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Don't know if there are any other ways that may be faster. If you are using HQL something like this should work:

Code:
Query query = session.createQuery("select cfg from ConfigID cfg order by cfg.id");
query.setMaxResults(1);
ConfigID cfg = (ConfigID)query.uniqueResult();


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.