Skip to content
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

Native @Query methods should allow Sort if Pageable can accept Sort anyway #2504

Closed
ullenboom opened this issue Apr 24, 2022 · 1 comment
Closed
Assignees
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@ullenboom
Copy link

I can write natives queries like

@Query( value = "SELECT * FROM Profile WHERE hornlength > ?1 ORDER BY hornlength DESC",
nativeQuery = true )
Page<Profile> findProfilesWithHornlengthGreaterThan( short minHornlength, Pageable pageable );

And call with

findProfilesWithHornlengthGreaterThan( (short) 4, PageRequest.of( 0, 10, Sort.by( "nickname" ) ) );

And the result will be

SELECT
    * 
FROM
    Profile 
WHERE
    hornlength > ? 
ORDER BY
    hornlength DESC,
    nickname asc
    limit ?

Good job of integrating nickname asc. But if this is possible, then Sort should be supported directly and not just indirectly via Pageable. However, using

List<Profile> findProfilesWithHornlengthGreaterThan( short minHornlength, Sort pageable );

leads to

Reason: Cannot use native queries with dynamic sorting in method public abstract java.util.List com.tutego.boot.jpa.repository.ProfileRepository.findProfilesWithHornlengthGreaterThan(short,org.springframework.data.domain.Sort); 

But writing PageRequest.of(0, Integer.MAX_VALUE, sort) would be the same as passing a Sort instance directly to the method.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 24, 2022
@gregturn gregturn self-assigned this May 16, 2022
@gregturn gregturn added type: enhancement A general enhancement in: query-parser Everything related to parsing JPQL or SQL and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 20, 2023
@gregturn
Copy link
Contributor

We don't support Sort in native queries, because that would require that we support ALL aspects of sorting. And native queries have very limited ability for us to do such. Using Sort as a way to slip in pagination is frankly something we are not ready to support at this time.

@gregturn gregturn added status: declined A suggestion or change that we don't feel we should currently apply and removed in: query-parser Everything related to parsing JPQL or SQL labels Apr 28, 2023
@gregturn gregturn closed this as not planned Won't fix, can't repro, duplicate, stale Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants