-->
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: How to do pagination in hibernates.
PostPosted: Thu Jan 18, 2007 9:25 am 
Beginner
Beginner

Joined: Mon Oct 30, 2006 12:46 am
Posts: 26
Hi ,

I am using dispaly tag at view to show the data using display tag pagination.

Now i want to do pagination thru hibernate.

here is my sample code :

String queryString = "from Student as model where model." + propertyName + " like :key";
Query queryObject = getSession().createQuery(queryString);
queryObject.setString("key","%"+value+ "%");
log.debug("Succesfully retrieving commmands");
return queryObject.list();


Here i want to retrieve first 20 rows and next like that.

pls help me !

Thanks
praveen


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 18, 2007 9:55 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:20 am
Posts: 40
Location: Vienna
Hi,

to get pagination, just use code like that (taken from the Hibernate reference):

Code:
Query q = sess.createQuery("from DomesticCat cat");
q.setFirstResult(20);
q.setMaxResults(10);
List cats = q.list();


best regards
Stefan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 18, 2007 9:58 am 
Regular
Regular

Joined: Wed Nov 17, 2004 11:49 am
Posts: 65
Location: Pittsburgh
If you read the javadoc on Query, you will see that there is a

setMaxResults(int) method and a setFirstResult(int) method. You would need to maintain the indexes in the client code.


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