Skip to content

Support findAll with sorting in derived query methods #2080

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
Thunderforge opened this issue Jun 10, 2021 · 3 comments
Closed

Support findAll with sorting in derived query methods #2080

Thunderforge opened this issue Jun 10, 2021 · 3 comments
Assignees
Labels
type: bug A general bug

Comments

@Thunderforge
Copy link

Consider this POJO code:

@RedisHash("somehash")
public class Example {

    @Id
    private String id;
    @Indexed
    private String some;
    @Indexed
    private String thing;
    @Indexed
    private Integer rank;

The following code would be expected to return elements sorted:

@Repository
public interface ExampleRepository extends CrudRepository<Example, string> {
    List<Example> findAllOrderByRank(Integer rank);
}

As described in this StackOverflow post) and corroborated by several users in the comments (and my own project), this does return all elements, but they are not sorted as expected. Indeed, the table of supported keywords inside method names does not list OrderBy as a valid keyword.

The section for Query By Example also specifically says that findAll with sorting is not supported.

This is important functionality that I would like to see supported in future releases.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 10, 2021
@mp911de
Copy link
Member

mp911de commented Jun 14, 2021

To simplify things, you're looking for sorting support through keywords/by passing in a Sort object into the query method. Query by Example isn't applicable in this context.

@mp911de mp911de self-assigned this Jun 14, 2021
@Thunderforge
Copy link
Author

Thunderforge commented Jun 15, 2021

Correct, I'm looking for sorting support through keywords (findAllOrderByFoo90) as well as passing in a Sort object into the query method.

My mistake with Query by Example; I assumed that since it called it out as an unsupported feature that there was a use case in which it was desirable.

For reference: we are in need of sorting functionality, and because findAll() (or findByBar()) returns an UnmodifiableList, our workaround involves duplicating the returned list and then sorting it through Java's List.sort(). It would be far easier, and more space efficient, to have orderBy working and returning a sorted list.

@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 15, 2021
@mp911de
Copy link
Member

mp911de commented Jun 15, 2021

After investigating the code, sorting has never worked. We need to fix that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants