spring-data-jpa icon indicating copy to clipboard operation
spring-data-jpa copied to clipboard

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

Open azizairo opened this issue 1 year ago • 2 comments

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);
	}

azizairo avatar May 15 '24 07:05 azizairo

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

quaff avatar May 16 '24 03:05 quaff

Ok, I will try to work on PR

azizairo avatar May 16 '24 07:05 azizairo