Skip to content

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

@azizairo

Description

@azizairo

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions