Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all results in one page using Spring Data Pagination

I want to get all the results in single page, I've tried with

Pageable p = new PageRequest(1, Integer.MAX_VALUE); return customerRepository.findAll(p); 

Above is not working, is there any methods to achieve this? Seems like it cannot be achieved from custom query as asked here.

like image 696
Ruwanka Madhushan Avatar asked Feb 05 '17 15:02

Ruwanka Madhushan


People also ask

How will you implement pagination using spring?

Once we have our repository extending from PagingAndSortingRepository, we just need to: Create or obtain a PageRequest object, which is an implementation of the Pageable interface. Pass the PageRequest object as an argument to the repository method we intend to use.

How does JPA pagination works internally?

You can use the JPA pagination for both entity queries and native SQL. To limit the underlying query ResultSet size, the JPA Query interface provides the setMaxResults method. Navigating the following page requires positioning the result set where the last page ended.

Which repository allows us to sort and retrieve the data in paginated way?

PagingAndSortingRepository PagingAndSortingRepository is an extension of CrudRepository to provide additional methods to retrieve entities using the pagination and sorting abstraction.


1 Answers

The more correct way is to use Pageable.unpaged()

Pageable wholePage = Pageable.unpaged(); return customerRepository.findAll(wholePage); 
like image 122
chekmare Avatar answered Oct 09 '22 11:10

chekmare