Home > Blockchain >  Spring data JPA pagination happens at db level or at application level
Spring data JPA pagination happens at db level or at application level

Time:06-16

Spring Data JPA supports pagination, but how does it work?

  1. Does JPA repository fetches all the data from database and deliver the chunks from application? (or)
  2. Does take chunks of data from database and deliver the data to client?

CodePudding user response:

It takes chunks of data from database. It does not fetch all of the data from database.

Generated query is using limit and offset with select query to fetch chunk of the data.

CodePudding user response:

The purpose of pagination is precisely to select exactly the page you want to retrieve. This avoids retrieving all the data in the DB, which can be a lot and can cause a performance problem for the application.

In fact, by passing the Pageable object to the method of a Spring Data Jpa repository, the pagination is applied on top of the query using the functionality of the database being used (such as limit and offset).

  • Related