Skip to content

Pageable - incorrect query for complex join for nativeQuery=true #2395

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

Open
tomaszba opened this issue Dec 31, 2021 · 1 comment
Open

Pageable - incorrect query for complex join for nativeQuery=true #2395

tomaszba opened this issue Dec 31, 2021 · 1 comment
Labels
in: query-parser Everything related to parsing JPQL or SQL type: bug A general bug

Comments

@tomaszba
Copy link

Hello,

spring-data-jpa, version: 2.3.9
database: mysql

An error occures for method annotated with @Query(nativeQuery=true) with declared pageable parameter, e.g.:

Page<NEntity> searchForEntityWithStatus(@Param("status"), Pageable pageable);

If query contains complex JOIN with ORDER BY and LIMIT, e.g.:

"LEFT JOIN( SELECT status FROM entity_statuses ORDER BY updated_at DESC LIMIT 1) st ON ..."

library generates wrong sorting and pagination fragment (ORDER BY is missing):

, some_column LIMIT ?,? which causes SQL error.

Workaroundthat working for me is to add at the end of query sentence like below:

ORDER BY <any_neutral_column>

any_neutral_column I mean column which has no impact on sorting.

@schauder schauder added in: query-parser Everything related to parsing JPQL or SQL type: bug A general bug labels Jan 3, 2022
@DiegoKrupitza
Copy link
Contributor

Could you provide a full SQL query (which has the bug)? Because then I can check if this bug is still present after introducing JSqlParser in #2417.

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

3 participants