-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Custom finders with PageRequest (instead of Pageable) method parameter causes IllegalArgumentException #2013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Further details says that this... Page<MyResult> findByStatusIn(Collection<Integer> status, PageRequest pageRequest); ...fails. But this... Page<MyResult> findByStatusIn(Collection<Integer> status, Pageable pageRequest); ...works. Should lead to a suitable test case. |
Confirmed. The first test case below works, the second one fails. @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 We need to possibly update the check for these parameters to do an |
… 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.
This should be fixed by spring-projects/spring-data-commons#2626. |
Thanks @odrotbohm. I'm going to add a couple test cases using this issue to ensure things are working. |
…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.
…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.
Mark Paluch opened DATAJPA-1718 and commented
A query using the
In
keyword accepting an array/collection and a PageRequest causes:IllegalArgumentException: At least 2 parameter(s) provided but only 1 parameter(s) present in query.
Repository declaration:
Stack trace:
Reference URL: https://gitter.im/spring-projects/spring-data?at=5eaab03a7975db7ebfd654a8
The text was updated successfully, but these errors were encountered: