-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed as not planned
Labels
status: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged
Description
Native Query Pagination Incorrectly Modifies String Literals
Issue Description
When using a native query with pagination in Spring Data JPA, the pagination clause fetch first ? rows only
is incorrectly inserted into string literals within the query, breaking the SQL syntax.
Reproducible Example
@Repository
public interface TestRepository extends PagingAndSortingRepository<Test, String> {
@Query(value = """
SELECT ';'
FROM test
""",
countQuery = """
SELECT count(*)
FROM test
""",
nativeQuery = true)
Page<QTestSearchRow> searchTest(Pageable pageable);
}
Expected Query
SELECT ';'
FROM test
fetch first ? rows only;
Actual Query
SELECT 'fetch first ? rows only;'
FROM test;
Impact
This issue affects any native query that contains string literals with semicolons, particularly impacting queries that use:
- String concatenation
- String aggregation (STRING_AGG in PostgreSQL)
- Complex string manipulations
Environment
- Spring Boot version: 3.3.4
- Spring Data JPA version: 3.3.4
- Database: PostgreSQL 16.4
Additional Notes
This is particularly problematic when using functions like STRING_AGG
where semicolons might be used as delimiters. For example:
STRING_AGG(column_name, ';')
would incorrectly become:
STRING_AGG(column_name, 'fetch first ? rows only;')
Metadata
Metadata
Assignees
Labels
status: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged