{"record":{"id":"f2c44133e3acb10e","repo":"quarkusio/quarkus","slug":"wrong-result-from-named-jpa-query-f2c441","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-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java","lineNumber":84,"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 myschema.Person\").executeUpdate());\n    }\n\n    private void persistNewPerson(String name) {","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java#L66-L102","documentation":"Postgres variant of the named-query assertion: createNamedQuery(\"get_person_by_name\") with name='Quarkus' returned an entity whose name is not 'Quarkus'. The @NamedQuery on Person or the underlying data is inconsistent with the test's expectation.","triggerScenarios":"Running the named query path in the jpa-postgresql base endpoint when the matching row was not stored correctly, the JPQL filter is wrong, or multiple/matching rows resolve to an unexpected entity.","commonSituations":"Entity @NamedQuery edited out of sync with test data, seeding inside a transaction that never committed, or stale database rows from earlier runs.","solutions":["Verify the @NamedQuery JPQL on the Person entity","Re-seed the 'Quarkus' Person inside a committed transaction before querying","Inspect the returned entity to identify which row matched","Clean the person table before the test for determinism"],"exampleFix":"// before\n@NamedQuery(name = \"get_person_by_name\", query = \"select p from Person p where p.name = :name\")\n// after (ensure commit before query)\nQuarkusTransaction.requiringNew().run(() -> em.persist(new Person(\"Quarkus\", ...)));\nTypedQuery<Person> typedQuery = em.createNamedQuery(\"get_person_by_name\", Person.class);","handlingStrategy":"validation","validationCode":"List<Person> matches = em.createNamedQuery(\"get_person_by_name\", Person.class)\n        .setParameter(\"name\", \"Quarkus\").getResultList();\nif (matches.size() != 1 || !\"Quarkus\".equals(matches.get(0).getName())) {\n    throw new IllegalStateException(\"NamedQuery returned: \" + matches);\n}","typeGuard":null,"tryCatchPattern":"try {\n    typedQuery.getSingleResult();\n} catch (PersistenceException e) {\n    throw new AssertionError(\"named query failed unexpectedly\", e);\n}","preventionTips":["Verify @NamedQuery definition against the test data after any entity change","Ensure seed data commits before the named query runs","Query the table directly when diagnosing data mismatches"],"tags":["jpa","named-query","postgresql","integration-test"],"backgroundTag":"jpa-named-query-wrong-result","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}