Consider sort defined by sortBy(…) in fluent Specification slice and unpaged queries. - #4298
Consider sort defined by sortBy(…) in fluent Specification slice and unpaged queries.#4298kmdy7991 wants to merge 1 commit into
Conversation
…ries. FetchableFluentQueryBySpecification now uses Pageable.getSortOr(…) to fall back to the sort defined via sortBy(…) when the given Pageable carries no sort, aligning slice(…) and the unpaged page(…) variants with FetchableFluentQueryByPredicate. Closes spring-projects#4297 Signed-off-by: kmdy7991 <kmdy7991@naver.com>
|
This is intentional behavior: and this is part of the contract: With that in mind, we need to revise |
4887543 to
c43320e
Compare
|
Thank you for the clarification — that makes sense, and I'm happy to rework this in that direction. Two things I noticed while looking into what the alignment would touch, just to scope it correctly:
Would you like me to rework this PR to do that — align FetchableFluentQueryByPredicate (and readPage(…)) on pageable.getSort(), update the Javadoc, and adjust the affected tests — or would you prefer to handle it on your side? Either way works for me. |
FetchableFluentQueryBySpecificationusespageable.getSort()inreadSlice(…)and in the unpaged branches ofslice(…),page(…), andpage(…, countSpec), so aPageablewithout a sort drops the sort configured throughsortBy(…). The Querydsl counterpart,FetchableFluentQueryByPredicate, usespageable.getSortOr(this.sort)in the analogous page/slice paths and keeps the fluent sort as the fallback.This change applies the same
getSortOr(…)fallback to the Specification variant and adds regression tests for the unsorted-PageRequestslice path and the unpaged terminals. The existing GH-3762 tests only usePageRequests that carry a sort (the override case), which is why the missing fallback went unnoticed.Tests:
./mvnw.cmd -pl spring-data-jpa -Dtest=UserRepositoryTests testCloses #4297