Module jakarta.data

Interface PageRequest<T>

Type Parameters:
T - entity class of the attributes that are used as sort criteria.

public interface PageRequest<T>

A request for a single well-specified page of query results.

A query method of a repository may have a parameter of type PageRequest if its return type indicates that it may return multiple entities, that is, if its return type is an array type, List, Stream, Page, or CursoredPage. The parameter of type PageRequest must occur after the method parameters representing regular parameters of the query itself. For example,

 @OrderBy("age")
 @OrderBy("ssn")
 Person[] findByAgeBetween(int minAge, int maxAge, PageRequest<Person> pageRequest);

 ...
 for (PageRequest<Person> p = PageRequest.of(Person.class).size(100);
      p != null; p = page.length == 0 ? null : p.next()) {
   page = people.findByAgeBetween(35, 59, p);
   ...
 }
 

A repository method may not be declared with:

  • more than one parameter of type PageRequest or Limit,
  • a parameter of type PageRequest and a parameter of type Limit, or
  • a parameter of type PageRequest in combination with the keyword First.

A repository method throws IllegalArgumentException if it is called with an argument of type PageRequest with nonempty sort criteria, and a separate argument or arguments of type Sort or Order.

A repository method throws DataException if the database is incapable of ordering the query results using the given sort criteria.