Skip to content
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

Sorting of Pageable.unpaged(sort) is ignored by JPA Repository #3476

Open
azizairo opened this issue May 15, 2024 · 2 comments
Open

Sorting of Pageable.unpaged(sort) is ignored by JPA Repository #3476

azizairo opened this issue May 15, 2024 · 2 comments
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement

Comments

@azizairo
Copy link

azizairo commented May 15, 2024

I have case when i need unpaged result with sort order. So to implement this i just used Pageable.unpaged method that allows to pass Sort parameter and I am expacting that jpa repository will return unpaged but sorted result. But it is not working cause jpa repostiory ignores sorting for unpaged request:

@Override
	public Page<T> findAll(Pageable pageable) {

		if (pageable.isUnpaged()) {
			return new PageImpl<>(findAll());
		}

		return findAll((Specification<T>) null, pageable);
	}

Is it possible to change behavior to this:

@Override
	public Page<T> findAll(Pageable pageable) {

		if (pageable.isUnpaged()) {
                        if(pageable.getSort().isSorted()) {
                              return new PageImpl<>(findAll(pageable.getSort()));
                        }
			return new PageImpl<>(findAll());
		}

		return findAll((Specification<T>) null, pageable);
	}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 15, 2024
@quaff
Copy link
Contributor

quaff commented May 16, 2024

I think it's reasonable, It's better to submit a PR instead.

@mp911de mp911de added type: enhancement A general enhancement status: ideal-for-contribution An issue that a contributor can help us with and removed status: waiting-for-triage An issue we've not yet triaged labels May 16, 2024
@azizairo
Copy link
Author

Ok, I will try to work on PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants