Skip to content

Syntax error when using setMaxResults() on native queries with SQL Server / PostgreSQL #2314

Closed
@yrodiere

Description

@yrodiere

With some versions of SQL Server / PostgreSQL, calling setMaxResults() on a native query results in parameters being added to the query:

https://github.com/hibernate/hibernate-orm/blob/018b8eeda3627e114ec25bd48407ccb9c47564ce/hibernate-core/src/main/java/org/hibernate/dialect/pagination/OffsetFetchLimitHandler.java#L40-L67

These parameters are added as ? and not whatever the Vert.x driver expects, resulting in errors such as this:

13:25:37,591 INFO  [database] 2025-06-19 11:25:34.446 UTC [65] ERROR:  syntax error at or near "?" at character 50
13:25:37,591 INFO  [database] 2025-06-19 11:25:34.446 UTC [65] STATEMENT:  Select * from books where author='4' fetch first ? rows only

See quarkusio/quarkus#48476


The root cause seems to be that:

  1. Hibernate Reactive usually processes the SQL to replace ? parameters with what the Vert.x driver expects:
  2. ... but that happens before the setMaxResults() SQL gets injected, therefore these injected parameters remain in the final SQL sent to the driver.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions