@Test // GH-2013
void findByCollectionWithPageable() {
flushTestUsers();
Page<User> userPage = repository.findByAgeIn(List.of(28, 35), (Pageable) PageRequest.of(0, 2));
assertThat(userPage).hasSize(2);
assertThat(userPage.getTotalElements()).isEqualTo(2);
assertThat(userPage.getTotalPages()).isEqualTo(1);
assertThat(userPage.getContent()).containsExactlyInAnyOrder(firstUser, secondUser);
@Test
void findByCollectionWithPageRequest() {
flushTestUsers();
Page<User> userPage = repository.findByAgeIn(List.of(28, 35), (PageRequest) PageRequest.of(0, 2));
assertThat(userPage).hasSize(2);
assertThat(userPage.getTotalElements()).isEqualTo(2);
assertThat(userPage.getTotalPages()).isEqualTo(1);
assertThat(userPage.getContent()).containsExactlyInAnyOrder(firstUser, secondUser);
The problem is based on Spring Data Commons, where Pageable
is on a special list, while PageRequest
is not.
https://github.com/spring-projects/spring-data-commons/blob/main/src/main/java/org/springframework/data/repository/query/Parameter.java#L60
We need to possibly update the check for these parameters to do an .IsInstance()
check.
… type that extend those types.
A custom finder with PageRequest, even though it extends Pageable, will fail when it would work fine with a narrowed input.
Related: spring-projects/spring-data-jpa#2013
See #2626.
… type that extend those types.
A custom finder with PageRequest, even though it extends Pageable, will fail when it would work fine with a narrowed input.
Related: spring-projects/spring-data-jpa#2013
See #2626.
Spring Data Commons has a hard-coded list of special types than can be included in query methods including Pageable and Sort.
A custom finder with PageRequest, even though it extends Pageable, will fail when it would work fine with a narrowed input. This extends the list using an isAssignableFrom check.
Related: spring-projects/spring-data-jpa#2013
See #2626.
Spring Data Commons has a hard-coded list of special types than can be included in query methods including Pageable and Sort.
A custom finder with PageRequest, even though it extends Pageable, will fail when it would work fine with a narrowed input. This extends the list using an assignability check.
Related: spring-projects/spring-data-jpa#2013
See #2626.
Spring Data Commons has a hard-coded list of special types than can be included in query methods including Pageable and Sort.
A custom finder with PageRequest, even though it extends Pageable, will fail when it would work fine with a narrowed input. This extends the list using an assignability check.
Related: spring-projects/spring-data-jpa#2013
See #2626.
Spring Data Commons has a hard-coded list of special types than can be included in query methods including Pageable and Sort.
A custom finder with PageRequest, even though it extends Pageable, will fail when it would work fine with a narrowed input. This extends the list using an assignability check.
Related: spring-projects/spring-data-jpa#2013
See #2626.
…arameter.
Spring Data Commons patched handling subclasses of special parameter types through spring-projects/spring-data-commons#2626. This commit adds test cases ensuring things work properly with Spring Data JPA.
See #2013.
changed the title
findBy<property>In(int[], PageRequest) causes IllegalArgumentException [DATAJPA-1718]
Custom finders with PageRequest method parameter causes IllegalArgumentException
May 12, 2022
changed the title
Custom finders with PageRequest method parameter causes IllegalArgumentException
Custom finders with PageRequest (instead of Pageable) method parameter causes IllegalArgumentException
May 12, 2022
…arameter.
Spring Data Commons patched handling subclasses of special parameter types through spring-projects/spring-data-commons#2626. This commit adds test cases ensuring things work properly with Spring Data JPA.
See #2013.
…arameter.
Spring Data Commons patched handling subclasses of special parameter types through spring-projects/spring-data-commons#2626. This commit adds test cases ensuring things work properly with Spring Data JPA.
See #2013.
Spring Data Commons patched handling subclasses of special parameter types through spring-projects/spring-data-commons#2626. This commit adds test cases ensuring things work properly with Spring Data JPA.
See #2013.
Spring Data Commons patched handling subclasses of special parameter types through spring-projects/spring-data-commons#2626. This commit adds test cases ensuring things work properly with Spring Data JPA.
See #2013.
Spring Data Commons patched handling subclasses of special parameter types through spring-projects/spring-data-commons#2626. This commit adds test cases ensuring things work properly with Spring Data JPA.
See #2013.