Adding the Limit parameter to the method declaration limits the number of results. However, this max currently cannot be 0 as when the query is executed an exception is thrown.
List<Foo> r = findByName(String name, Limit.of(0));
// org.springframework.dao.InvalidDataAccessApiUsageException: Page size must not be less than one
This behaviour is not documented anywhere near the Limit class. There's a vague explanation which does not explain things:
|
* {@link Limit} itself does not make assumptions about the actual {@link #max()} value sign. This means that a negative |
|
* value may be valid within a defined context. |
|
* |
|
* @author Christoph Strobl |
|
* @author Oliver Drotbohm |
|
* @since 3.2 |
|
*/ |
|
public sealed interface Limit permits Limited, Unlimited { |
Instead, Pageable and PageRequest mention the "size" must be non zero:
|
* @param pageSize the size of the page to be returned, must be greater than 0. |
|
* @return a new {@link Pageable}. |
|
* @since 2.5 |
|
*/ |
|
static Pageable ofSize(int pageSize) { |
My question: should the documentation of Limit be updated to reflect this, or we should indeed allow the limit to be zero, which should return an empty result list. This'd be consistent with how usual SQL statements are expected to behave,
Adding the
Limitparameter to the method declaration limits the number of results. However, thismaxcurrently cannot be 0 as when the query is executed an exception is thrown.This behaviour is not documented anywhere near the
Limitclass. There's a vague explanation which does not explain things:spring-data-commons/src/main/java/org/springframework/data/domain/Limit.java
Lines 30 to 37 in 0a603f2
Instead,
PageableandPageRequestmention the "size" must be non zero:spring-data-commons/src/main/java/org/springframework/data/domain/Pageable.java
Lines 54 to 58 in 0a603f2
My question: should the documentation of
Limitbe updated to reflect this, or we should indeed allow the limit to be zero, which should return an empty result list. This'd be consistent with how usual SQL statements are expected to behave,