Skip to content

Sorting by function result not possible if function contains parameter and Sort.by is used [DATAJPA-1750] #2045

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
spring-projects-issues opened this issue Jun 28, 2020 · 6 comments
Assignees
Labels
in: query-parser Everything related to parsing JPQL or SQL type: bug A general bug

Comments

@spring-projects-issues
Copy link

simonparadies opened DATAJPA-1750 and commented

The FUNCTION_PATTERN regex in QueryUtils does not match functions containing positional or named parameters. Therefore, in these cases, the order by clause is constructed using the entities' qualifier, which leads to an incorrect expression


Affects: 2.4 M1 (2020.0.0)

Referenced from: pull request #425

@spring-projects-issues
Copy link
Author

Jens Schauder commented

Could you provide a specific example where it fails?

@spring-projects-issues
Copy link
Author

simonparadies commented

See the tests in the linked PR

@spring-projects-issues
Copy link
Author

Jens Schauder commented

Strange I didn't see that. Thanks

@luitas
Copy link

luitas commented May 19, 2022

On 2.5.12 spring boot it works bu in 2.5.13 not working
In my case if i have

pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "inserted"));
return dataRecordRepository.findAllByFilter(pageable,1);

and in repository

@Query("select r From DataRecord r " +
            "  " +
            "where " +
                    " ( " +
            "       r.adusrId = :userId " +
            "       or EXISTS( select 1 FROM DataRecordDvsRight dr WHERE dr.adusrId = :userId AND dr.dataRecord = r ) " +
            ")")
    Page<DataRecord> findAllByFilter(Pageable pageable, @Param("userId") Long userId);

I get an error:
Invalid path: 'dr.inserted' [select r From com.algoritmusistemos.media.app.entity.DataRecord r where ( r.adusrId = :userId or EXISTS( select 1 FROM com.algoritmusistemos.media.app.entity.DataRecordDvsRight dr WHERE dr.adusrId = :userId AND dr.dataRecord = r ) ) order by dr.inserted desc]

@schauder
Copy link
Contributor

Seems to be related to, possibly a duplicate of #2496

gregturn added a commit that referenced this issue May 19, 2022
By properly parsing "order by" clauses, Spring Data JPA can apply sorting parameters to the end of queries in the event of complex queries that involve nested subselects.

Closes ##2496, #2522, #2537, #2045.
gregturn added a commit that referenced this issue May 19, 2022
By properly parsing "order by" clauses, Spring Data JPA can apply sorting parameters to the end of queries in the event of complex queries that involve nested subselects.

Closes ##2496, #2522, #2537, #2045.
gregturn added a commit that referenced this issue May 19, 2022
By properly parsing "order by" clauses, Spring Data JPA can apply sorting parameters to the end of queries in the event of complex queries that involve nested subselects.

Closes ##2496, #2522, #2537, #2045.
gregturn added a commit that referenced this issue May 19, 2022
By properly parsing "order by" clauses, Spring Data JPA can apply sorting parameters to the end of queries in the event of complex queries that involve nested subselects.

Closes ##2496, #2522, #2537, #2045.
@gregturn gregturn self-assigned this May 19, 2022
@gregturn gregturn added this to the 3.0 M5 (2022.0.0) milestone May 19, 2022
gregturn added a commit that referenced this issue May 19, 2022
By properly parsing "order by" clauses, Spring Data JPA can apply sorting parameters to the end of queries in the event of complex queries that involve nested subselects.

Closes ##2496, #2522, #2537, #2045.
gregturn added a commit that referenced this issue May 19, 2022
By properly parsing "order by" clauses, Spring Data JPA can apply sorting parameters to the end of queries in the event of complex queries that involve nested subselects.

Closes ##2496, #2522, #2537, #2045.
@gregturn
Copy link
Contributor

Backported to 2.7.x and 2.6.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: query-parser Everything related to parsing JPQL or SQL type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants