You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a native SQL query and applying a Pageable with sorting, the generated SQL can become malformed with missing order by clause when inner order by clauses exist in query
#3823
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.
Description:
When using a native SQL query and applying a Pageable with sorting, the generated SQL can become malformed with missing order by clause when inner order by clauses exist in query
To reproduce:
Create a native query string with some inner selects with order clauses
End inner select like " order by something desc)"
Run query and get error like "ORA-00933: SQL command not properly ended..." in Oracle
Notice logged SQL end with: "where (...), something desc fetch first ? rows only"
Details:
I had a look at JPA repository query package to look for hints for problems with my SQL. Found this:
applySorting is used to either append ", " or " order by " to a query.
hasOrderByClause is used to determine if top-level "order by" exists: countOccurrences(ORDER_BY, query) > countOccurrences(ORDER_BY_IN_WINDOW_OR_SUBSELECT, query).
ORDER_BY_IN_WINDOW_OR_SUBSELECT only matches order by within ( ).
Workaround:
Added "order by null" to native query
Run query
Notice logged SQL end with: "where (...) order by null, something desc fetch first ? rows only"
The text was updated successfully, but these errors were encountered:
Thanks for reaching out. Our own support is limited to simple queries only as we do not maintain a fully SQL compliant parser, instead we apply limited regex replacements. If you want to use more complex queries, please add JSqlParser (see reference docs) or provide the count query yourself.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.
Description:
When using a native SQL query and applying a Pageable with sorting, the generated SQL can become malformed with missing order by clause when inner order by clauses exist in query
To reproduce:
Details:
I had a look at JPA repository query package to look for hints for problems with my SQL. Found this:
https://github.com/spring-projects/spring-data-jpa/blame/dbd4e532d2eb229b8449458f7851e9ec6e814cfc/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java#L301
In QueryUtils
Workaround:
The text was updated successfully, but these errors were encountered: