Skip to content

Sorting doesn't work for field alias [DATAJPA-1061] #1404

@spring-projects-issues

Description

@spring-projects-issues

Sergey Skryabin opened DATAJPA-1061 and commented

    @Query("SELECT c.name AS n FROM cats c")
    List<String> findCats(Sort sort);
...
    findCats(new Sort("n"));

doesn't work ("The state field path 'c.n' cannot be resolved to a valid type."). Although

    @Query("SELECT lower(c.name) AS n FROM cats c")
    List<String> findCats(Sort sort);
...
    findCats(new Sort("n"));

works fine.

http://docs.spring.io/spring-data/jpa/docs/1.11.x/reference/html/#jpa.query-methods.sorting
says: The properties actually used within the Order instances of Sort need to match to your domain model, which means they need to resolve to either a property or an alias used within the query.


Affects: 1.11 GA (Ingalls)

Attachments:

Referenced from: pull request #276

Backported to: 2.1.10 (Lovelace SR10), 1.11.23 (Ingalls SR23)

3 votes, 9 watchers

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions