{"record":{"id":"b4cab7aee07aec62","repo":"quarkusio/quarkus","slug":"incorrect-number-of-results-b4cab7","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-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java","lineNumber":81,"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":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java#L63-L99","documentation":"A RuntimeException thrown by the JPAFunctionalityTestEndpoint.base smoke test when a Criteria query over Person returns a list whose size is not exactly 3. It indicates the database state (seeded persons) or query mapping differs from what the test expects. It is application-level test validation, not an ORM failure.","triggerScenarios":"Running GET on the test endpoint after the Person table contains fewer or more than the 3 expected rows (Gizmo, Quarkus, etc.) - e.g. leftover data from a previous run or a failed seed step.","commonSituations":"Dirty database between test runs, concurrent tests mutating Person rows, or a changed persistence.xml/orm.xml that altered which entities are persisted.","solutions":["Reset the database before the test run (drop/recreate schema or use a clean test container)","Remove leftover Person rows from prior failed runs","Verify the test setup/seed code that inserts exactly 3 Person entities actually ran"],"exampleFix":"// before\nList<Person> allpersons = q.getResultList();\nif (allpersons.size() != 3) {\n    throw new RuntimeException(\"Incorrect number of results\");\n}\n// after\nem.createQuery(\"delete from Person\").executeUpdate(); // reset state in test setup\nList<Person> allpersons = q.getResultList();\nassertEquals(3, allpersons.size());","handlingStrategy":"validation","validationCode":"long count = em.createQuery(\"select count(p) from Person p\", Long.class).getSingleResult();\nboolean datasetReady = count == 3;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reset/clean the Person table in test setup before assertions","Make each test transactional with rollback to avoid dirty state","Assert seed data was created before running query assertions"],"tags":["jpa","hibernate","test-assertion","postgresql"],"backgroundTag":"unexpected-query-result-count","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"}