Module jakarta.data
Package jakarta.data

Record Class Limit

java.lang.Object
java.lang.Record
jakarta.data.Limit
Record Components:
maxResults - maximum number of results for a query.
startAt - starting position for query results (1 is the first result).

public record Limit(int maxResults, long startAt) extends Record

Specifies a limit on the number of results retrieved by a repository method. The results of a single invocation of a repository method may be limited to a given maximum number of results or to a given positioned range defined in terms of an offset and maximum number of results.

A query method of a repository may have a parameter of type Limit if its return type indicates that it may return multiple entities. The parameter of type Limit must occur after the method parameters representing regular parameters of the query itself. For example,

 Product[] findByNameLike(String namePattern, Limit limit, Sort<?>... sorts);
 
 ...
 mostExpensive50 = products.findByNameLike(pattern, Limit.of(50), Sort.desc("price"));
 ...
 secondMostExpensive50 = products.findByNameLike(pattern, Limit.range(51, 100), Sort.desc("price"));
 

A repository method may not be declared with:

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