RSS

Pagination with Java Hibernate Criteria

13 Mar

Hibernate is most popular technology in Java development. Most of the real world application they used kind of hibernate technology with fine tuned mechanisms. If you are in java development I hope the following code snippet will be helpful you to make your application faster.

What I’m going to explain in this post is how to load the chunk of data with efficient manner.
Hibernate Criteria helps to do this as we wish. Think about if you have millions of data in your data table and you are going to display the data in your application. Check the following code snippet

You can see in the above example I have used two numbers to query the data from back end. The pageNumber means which page that your are in and the recordesPerPage will use to filter the max record count going to be query. Then the each time fetch the data from database by given range.

This will really make the performance gain rather than loading whole chunk of data.

Advertisements
 
5 Comments

Posted by on March 13, 2014 in java, mysql

 

Tags: , , ,

5 responses to “Pagination with Java Hibernate Criteria

  1. Shiva

    January 7, 2015 at 7:39 am

    Where is the example? i don’t see it

     
  2. Ram

    October 14, 2015 at 5:17 am

    what is the need for the transaction here !? to just read the data from DB!

     
    • malalanayake

      October 14, 2015 at 12:42 pm

      Hibernate Transaction and Database level transaction is different. Even it is read operation you have to create the hibernate transaction but you don’t need database transaction. If you want you can set the transaction type read only in hibernate level. Then it is not going to create the database level transaction. I hope you got the answer.

       
  3. Kris

    January 10, 2016 at 1:04 pm

    hello, in the jsp file, how do you make the scriplet?

     
    • santosh

      June 27, 2016 at 4:28 pm

      You are not supposed to do it in scriptlet.

       

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: