Skip to content

PagingAndSortingRepository.findAll(Pageable) ignores an unpaged Pageable with a sorted Sort #3676

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

Closed
demonfiddler opened this issue Nov 13, 2024 · 3 comments
Labels
status: duplicate A duplicate of another issue

Comments

@demonfiddler
Copy link

Passing an unpaged Pageable containing a sorted Sort to the PagingAndSortingRepository.findAll(Pageable) method ignores the Pageable's Sort, generating an SQL SELECT statement that is missing the requisite ORDER BY clause. The following code fragment illustrates the problem:

List<Order> orders = List.of(Order.asc("sortProperty"));
Sort sort = Sort.by(orders);
Pageable pageable = Pageable.unpaged(sort);
ListPagingAndSortingRepository<T, ID> repository = ...;
Page<T> unsortedPage = repository.findAll(pageable);
List<T> sortedContent = repository.findAll(sort);
assert unsortedPage.getContent().equals(sortedContent) : "The findAll(Pageable) overload does not sort the content";
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 13, 2024
@mp911de
Copy link
Member

mp911de commented Nov 14, 2024

In which project and version did you experience this issue? In JPA, we added this enhancement with 3.4 M1 (#3476)

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Nov 14, 2024
@demonfiddler
Copy link
Author

My apologies, it was remiss of me to omit the version info. I am using Spring Boot version 3.3.5 and the problem manifests through spring-boot-starter-data-jpa. Sounds like I should upgrade to 3.4 once it's released. In the meantime I have a workaround which is to call the findAll(Sort) method when an unsorted Pageable is passed.

(BTW before raising this issue I did search the spring-data-commons project for any issues relating to PagingAndSortingRepository but didn't find any of relevance.)

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 14, 2024
@mp911de mp911de transferred this issue from spring-projects/spring-data-commons Nov 14, 2024
@mp911de
Copy link
Member

mp911de commented Nov 14, 2024

No worries. It could be that the issue affects other modules as well. Closing this one and moving it to JPA.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2024
@mp911de mp911de added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants