Question: How can I get all the records for `findAll ()` service using pagination and `Spring Data JPA` when we do not apply filters it should return all the records rather than displaying it pagewise.I have `findAll (Pageable pageable)` service and calling it from custom repository. IS it possible to get all the records in one page only using pagination?

Answer: 
```
public interface UserRepository extends PagingAndSortingRepository<User, Long> {
    //Page<User> findAll(Pageable pageable); is already in this repository.
}

```

So just in case you want to find the first page of size 20 try:

```
Page<User> users = repository.findAll(new PageRequest(0, 20));

```

If what you want to do is to get all entities on a single page, it doesn't make much sense but can be done in two steps:

```
int count = repository.count();
Page<User> users = repository.findAll(new PageRequest(0, count));

```

`count()` comes from `CrudRepository` which is extended by `PagingAndSortingRepository`.
Step 1:

In your repository,implement the interface JpaSpecificationExecutor, which as overloaded findAll method, which accepts the Specification Object and page object created above.

```
The method signature in interface is:    Page<T> findAll(@Nullable Specification<T> spec, Pageable pageable);

```

The repository class looks like this:

```
@Repository
public interface MyRepository extends
  CrudRepository<JobRecord, Long>,
  JpaSpecificationExecutor<JobRecord> {

```

Implement your custom specification with predicates

```
  static Specification<JobRecord> findByParam1AndParam2AndParam3(String param1,String param2,String param3) {
    return (jobRecord, cq, builder) -> {
      List<Predicate> predicates = new ArrayList<>();
      predicates.add(builder.equal(jobRecord.get("param1"), "param1"));
      predicates.add(builder.equal(jobRecord.get("param2"), "param2"));
      predicates.add(builder.equal(jobRecord.get("param3"), "param3"));
      // we can add  sorting here
      cq.orderBy(cb.desc(jobRecord.get("submittedAt")));
    // AND all predicates
      return builder.and(predicates.toArray(new Predicate[0]));
    };
  }

```

Step 2:

In your Service, create a Pageable page object as:

```
Pageable page = PageRequest.of(0, 5);// 0 is the firstResult and 5 is pageSize which we can fetch from queryParams 

```

The findAll method can be used with pagination as:--

```
List<Job> jobs = repository.findAll(findByParam1AndParam2AndParam3("param1","param2","param3"), page)
      .stream()
      .map(JobRecord::toModel)
      .collect(Collectors.toList());
    return new JobList().jobList(jobs);

```