{"record":{"id":"637cf326e57cc58f","repo":"quarkusio/quarkus","slug":"incorrect-number-of-results-637cf3","errorCode":null,"errorMessage":"Incorrect number of results","messagePattern":"Incorrect number of results","errorType":"http","errorClass":"RuntimeException","httpStatus":500,"severity":"error","filePath":"integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java","lineNumber":63,"sourceCode":"\n        //Store some well known Person instances we can then test on:\n        QuarkusTransaction.requiringNew().run(() -> {\n            persistNewPerson(\"Gizmo\");\n            persistNewPerson(\"Quarkus\");\n            persistNewPerson(\"Hibernate ORM\");\n        });\n\n        //Load all persons and run some checks on the query results:\n        QuarkusTransaction.requiringNew().run(() -> {\n            CriteriaBuilder cb = em.getCriteriaBuilder();\n\n            CriteriaQuery<Person> cq = cb.createQuery(Person.class);\n            Root<Person> from = cq.from(Person.class);\n            cq.select(from).orderBy(cb.asc(from.get(\"name\")));\n            TypedQuery<Person> q = em.createQuery(cq);\n            List<Person> allpersons = q.getResultList();\n            if (allpersons.size() != 3) {\n                throw new RuntimeException(\"Incorrect number of results\");\n            }\n            if (!allpersons.get(0).getName().equals(\"Gizmo\")) {\n                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();","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java#L45-L81","documentation":"Same assertion as the MySQL variant, but in the jpa-postgresql integration test endpoint (RAISED IN base, a public test endpoint method). A Criteria query for all Person entities ordered by name returned a list whose size is not the expected 3, so the endpoint throws.","triggerScenarios":"GET to the base test endpoint while the PostgreSQL database holds a Person count other than 3 at query time — failed seeding, leftover rows from prior runs, or cleanup not executed.","commonSituations":"Stale PostgreSQL test database state, container-based test DB not reset between runs, or seed transaction rolled back silently.","solutions":["Dump the person table in PostgreSQL to compare actual vs expected rows","Run cleanUpData() before seeding to make the test idempotent","Wrap seeding in QuarkusTransaction.requiringNew() so it commits before the query","Reset the test database/container between runs"],"exampleFix":"// before\nif (allpersons.size() != 3) {\n    throw new RuntimeException(\"Incorrect number of results\");\n}\n// after\ncleanUpData();\nQuarkusTransaction.requiringNew().run(() -> seedData());\nif (allpersons.size() != 3) {\n    throw new RuntimeException(\"Incorrect number of results: \" + allpersons.size());\n}","handlingStrategy":"validation","validationCode":"long count = (Long) em.createQuery(\"select count(p) from Person p\").getSingleResult();\nif (count != 3) {\n    throw new IllegalStateException(\"Expected 3 Person rows, found \" + count);\n}","typeGuard":null,"tryCatchPattern":"try {\n    q.getResultList();\n} catch (RuntimeException e) {\n    throw new AssertionError(\"unexpected Person row count in PostgreSQL: \" + e.getMessage(), e);\n}","preventionTips":["Clean and re-seed the database at the start of each endpoint invocation","Use container-per-test lifecycle so each run starts from a fresh PostgreSQL","Include actual row count in assertion messages"],"tags":["jpa","postgresql","integration-test","assertion"],"backgroundTag":"jpa-query-result-count-mismatch","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"}