Pagination Example Hibernate

Pagination Example Hibernate

Pagination Hibernate Tutorial

If Hibernate fetches large amount of data (records) from the database, it consumes lot of memory. To consume less RAM memory, the data can be obtained in installments from the database. One solution is using pagination


The idea behind Pagination Hibernate is to divide the large result set into a number of pages and fetching one page at a time. We can programmatically declare how many records should contain each page and from what record. For example, the page may contain 5 records staring from 3rd record.

The code is simple to do the job of Pagination Hibernate.

Previous First program – Student is used. Just change the client program.

Think there are 7 records (counting 0 to 6) in school table. We make three pages where 2 records, 3 records and 3 records are fetched each time (three database hits are made). End fetching gets only 2 records.

Program on Pagination
File Name: PaginationClient,java

Pagination Hibernate

Note 1: Observe, for each fetch, one database hit is made. First fetch 2 records, second fetch 3 records and last fetch 2 records are obtained.

Note 2: It saves time also (or increases performance); for a number of records (one page) only one database hit is made.

Leave a Reply

Your email address will not be published. Required fields are marked *