• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Can Hibernate alone implement pagination?

 
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to implement a pagination concept, where a page shows only a limited subset (say, 10 Items) at a time, and users can navigate to the next and previous pages manually.



This code produces 1st 20 records. But what about navigation to another page, where next set of 20 records are displayed?

Can Hibernate alone solve this problem, without going into other libraries like Display tag libraries & Jsp taglib?
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kunal,

you can do that by using setFirstResult() method.

Check this Example
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Hemant Thard. It fetches me required number of records in a jsp page. But how to navigate to another page where it will fetch me another set of records. Should i run the servlet & Dao class again?
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All you need to do is a little math. No frameworks needed for that.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear Bibeault.
I have fetched all the 30records, but i need to display them 5 at a page, each record with 2 radio buttons.

Should i call servlet & dao class again,but that will be a lot of db hits? Or should i have a link in jsp page invoking the dao code with next page number appended to the url?

Or should i invoke the dao code from jsp with page number incremented by 1? No i guess that's a bad idea

Can you please provide me some hint?
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One option is to use code something like this



Or, put the code which are in scriplet into a servlet, and call it each time . But, will that be efficient, if need to go for 70Records, 5 at a time, that too with 2 radio buttons, for getting user choice?
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more thing setFirstResult() returns the record stating from the arg value. But i need random records
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since i have the list of random Records, i should go for some that implements it in jsp itself, any way of iterating into the list for 5records
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear Bibeault, what should i do?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kunal, if you got the solution, let us know. i am facing the same problem
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is solved by implementing pagination in jsp, not via hibernate
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All you need to do is keep track of which page number you want to look at, and do a little math to figure out what the value to pass to setFirstResult().
 
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic