Closed spring-projects-issues closed 2 years ago
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 Pageable
is on a special list, while PageRequest
is not.
We need to possibly update the check for these parameters to do an .IsInstance()
check.
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.
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