Why is this an issue?

Spring Data Repository supports paging for queries, allowing you to return results in small, manageable chunks rather than retrieving an entire large result set.

The conventional approach to paginating data in Spring is to use the Pageable interface to control pagination and to store the query results into a Page or Slice. If a query declaration in a Spring Data Repository returns a Page or Slice without taking a Pageable as an input, it raises a runtime exception.

This rule raises an issue on queries in a Repository that return a Page or Slice without taking a Pageable as an input.

How to fix it

Ensure that query methods returning a Page or Slice include a Pageable parameter in their method signature.

Code examples

Noncompliant code example

interface ItemRepository extends JpaRepository<Item, Long> {
    Page<Item> findItems(); //non compliant, no Pageable parameter
}

Compliant solution

interface ItemRepository extends JpaRepository<Item, Long> {
    Page<Item> findItems(Pageable pageable);
}

Resources

Documentation

Articles & blog posts