Skip to content

Query.setMaxResults results in wrong SQL queries against MSSQL/Postgres when using native queries #48476

@mjurc

Description

@mjurc

Describe the bug

Having a statement like

    @GET
    @Path("books/author/{authorId}")
    public Uni<Response> findFirstBooksByAuthor(Integer authorId) {
        return factory.withSession(
                session -> session.createNativeQuery("Select * from books where author='" + authorId + "'", Book.class)
                        .setMaxResults(1)
                        .getResultList()
                        .map(books -> Response.ok(books).build()));
    }

results in errors like the following writeout on MSSQL/PostgreSQL:

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

Expected behavior

The method call returns correct query (with correct number of rows injected into the query)

Actual behavior

The method call returns query against MSSQL/PostgreSQL database like

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

How to Reproduce?

git clone [email protected]:mjurc/quarkus-test-suite.git && cd quarkus-test-suite/sql-db/hibernate-reactive && git checkout 5df58dfac0984aed7a01b1eb4a166ac58f2929f1
mvn clean verify -Dit.test=MsSQLDatabaseHibernateReactiveIT#searchWithLimit,PostgresqlDatabaseHibernateReactiveIT#searchWithLimit

Output of uname -a or ver

Linux donnager 6.14.11-300.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jun 10 16:24:16 UTC 2025 x86_64 GNU/Linux

Output of java -version

openjdk version "21.0.7" 2025-04-15 OpenJDK Runtime Environment (Red_Hat-21.0.7.0.6-2) (build 21.0.7+6) OpenJDK 64-Bit Server VM (Red_Hat-21.0.7.0.6-2) (build 21.0.7+6, mixed mode, sharing)

Quarkus version or git rev

main ; 3.24

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.9 (Red Hat 3.9.9-14)

Additional information

Tested DBs:

  • docker.io/library/postgres:17
  • mcr.microsoft.com/mssql/rhel/server:2022-latest

Other DBs (Maria, MySQL) don't seem to have this issue

Metadata

Metadata

Assignees

Labels

area/hibernate-reactiveHibernate Reactivekind/bug-thirdpartyBugs that are caused by third-party components and not causing a major dysfunction of core Quarkus.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions