-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 with #sort generates a broken query #3546
Comments
spring-projects-issues
added
the
status: waiting-for-triage
An issue we've not yet triaged
label
Jul 23, 2024
mp911de
added
type: bug
A general bug
and removed
status: waiting-for-triage
An issue we've not yet triaged
labels
Jul 24, 2024
Thanks for the report. This is a leftover from the earlier restrictions on native query sorting. Meanwhile, we've added support for query enhancing through JSQLParser that should lift the restriction for many cases where the regex-based enhancer isn't capable of adding We should remove this requirement to avoid the need for custom string replacement. |
mp911de
added a commit
that referenced
this issue
Jul 24, 2024
We now no longer check for #sort in native queries to apply sorting directly. This was a leftover from earlier query rewriting. Closes #3546
mp911de
added a commit
that referenced
this issue
Jul 24, 2024
We now no longer check for #sort in native queries to apply sorting directly. This was a leftover from earlier query rewriting. Closes #3546
Thanks @mp911de ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Although the docs mention that dynamic sorting is not supported with native queries, the following almost works:
It generates the following query when sorting by a
title
field:select * from show #sort ORDER BY title asc
.Note that it added the correct ORDER BY, but didn't remove the
#sort
placeholder.I've created a simple example to reproduce here: https://github.com/paulbakker/spring-data-jpa-sort-bug.
See the README for details about the code.
The example uses a Postgres Testcontainer, so no extra setup is needed.
A hacky workaround is to add a custom query rewrite like this:
The text was updated successfully, but these errors were encountered: