Closed as not planned
Description
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:
In QueryUtils
- 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"
Metadata
Metadata
Assignees
Labels
No labels