{"record":{"id":"12b1de40ca129cb7","repo":"quarkusio/quarkus","slug":"wrong-result-from-named-jpa-query-12b1de","errorCode":null,"errorMessage":"Wrong result from named JPA query","messagePattern":"Wrong result from named JPA query","errorType":"http","errorClass":"RuntimeException","httpStatus":500,"severity":"error","filePath":"integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/JPAFunctionalityTestEndpoint.java","lineNumber":77,"sourceCode":"                throw new RuntimeException(\"Incorrect order of results\");\n            }\n            StringBuilder sb = new StringBuilder(\"list of stored Person names:\\n\\t\");\n            for (Person p : allpersons) {\n                p.describeFully(sb);\n            }\n            sb.append(\"\\nList complete.\\n\");\n            System.out.print(sb);\n        });\n\n        //Try a JPA named query:\n        QuarkusTransaction.requiringNew().run(() -> {\n            TypedQuery<Person> typedQuery = em.createNamedQuery(\n                    \"get_person_by_name\", Person.class);\n            typedQuery.setParameter(\"name\", \"Quarkus\");\n            final Person singleResult = typedQuery.getSingleResult();\n\n            if (!singleResult.getName().equals(\"Quarkus\")) {\n                throw new RuntimeException(\"Wrong result from named JPA query\");\n            }\n        });\n\n        //Check that HQL fetch does not throw an exception\n        QuarkusTransaction.requiringNew()\n                .run(() -> em.createQuery(\"from Person p left join fetch p.address a\").getResultList());\n\n        cleanUpData();\n\n        return \"OK\";\n    }\n\n    private void cleanUpData() {\n        QuarkusTransaction.requiringNew()\n                .run(() -> em.createNativeQuery(\"Delete from Person\").executeUpdate());\n    }\n\n    private void persistNewPerson(String name) {","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/JPAFunctionalityTestEndpoint.java#L59-L95","documentation":"The endpoint executes named query 'get_person_by_name' with parameter 'Quarkus' and asserts the single returned Person has name 'Quarkus'; any other value throws this RuntimeException. Same failure family as the MariaDB variant but on SQL Server — it flags wrong query mapping, wrong matched row, or data issues.","triggerScenarios":"getSingleResult() of the named query returns a Person whose getName() != 'Quarkus' — the query's WHERE clause matches a different row (duplicates, wrong column) or the entity mapping is inconsistent.","commonSituations":"Duplicate/leftover 'Quarkus'-adjacent rows; @NamedQuery filtering on the wrong column; MSSQL collation causing unexpected matches; failed cleanup leaving older fixtures.","solutions":["Run cleanUpData before seeding to guarantee a deterministic table","Inspect the get_person_by_name @NamedQuery WHERE clause and column mapping","Query the table directly in SQL Server to see which rows match name='Quarkus'","Consider a unique constraint on Person.name for test determinism"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"List<Person> matches = em.createNamedQuery(\"get_person_by_name\", Person.class)\n        .setParameter(\"name\", \"Quarkus\").getResultList();\nif (matches.size() != 1 || !matches.get(0).getName().equals(\"Quarkus\")) {\n    throw new IllegalStateException(\"get_person_by_name returned unexpected data\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Person p = typedQuery.getSingleResult();\n} catch (RuntimeException e) {\n    // verify named-query definition and table contents before retrying\n}","preventionTips":["Reset table state before each test run","Keep named queries aligned with actual column mappings","Enforce unique constraints on queried columns","Verify with raw SQL which rows match the filter"],"tags":["jpa","named-query","mssql","integration-test"],"backgroundTag":"unexpected-query-result","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}