{"record":{"id":"2e171acb49ad6758","repo":"quarkusio/quarkus","slug":"incorrect-number-of-results-2e171a","errorCode":null,"errorMessage":"Incorrect number of results","messagePattern":"Incorrect number of results","errorType":"http","errorClass":"RuntimeException","httpStatus":500,"severity":"error","filePath":"integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/JPAFunctionalityTestEndpoint.java","lineNumber":52,"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":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/JPAFunctionalityTestEndpoint.java#L34-L70","documentation":"This is a hand-written assertion inside the Quarkus jpa-mysql integration test endpoint. After running a Criteria API query selecting all Person entities ordered by name, the test expects exactly 3 rows; if the persistence layer returned a different count, it throws this RuntimeException. It signals that data setup, persistence, or the query did not behave as expected.","triggerScenarios":"Calling testTestEndpoints' criteria-query path when the number of Person rows in the MySQL database differs from 3 — e.g. seed data failed to persist, the transaction rolled back, previous test runs left stale rows, or cleanup (cleanUpData) did not run before seeding.","commonSituations":"Database state pollution from a prior failed run, MySQL schema/dialect issues causing a partially applied persist, or HQL/Criteria mapping changes returning more or fewer rows than expected.","solutions":["Inspect the actual size of allpersons and dump the Person table in MySQL to find the extra/missing rows","Ensure cleanUpData() runs before seeding so repeated invocations don't accumulate rows","Verify the seeding transaction committed (QuarkusTransaction.requiringNew) and no rollback occurred","Rebuild the schema from scratch (drop/create) to rule out stale state"],"exampleFix":"// before\nif (allpersons.size() != 3) {\n    throw new RuntimeException(\"Incorrect number of results\");\n}\n// after\ncleanUpData(); // guarantee a clean slate before seeding\nimport io.quarkus.narayana.jta.QuarkusTransaction;\nQuarkusTransaction.requiringNew().run(() -> seedData());\nif (allpersons.size() != 3) {\n    throw new RuntimeException(\"Incorrect number of results: \" + allpersons.size());\n}","handlingStrategy":"validation","validationCode":"// before the assertion, verify DB state\nList<Person> all = em.createQuery(\"select p from Person p\", Person.class).getResultList();\nif (all.size() != 3) {\n    throw new IllegalStateException(\"Expected 3 Person rows, found \" + all.size() + \": \" + all.stream().map(Person::getName).toList());\n}","typeGuard":null,"tryCatchPattern":"try {\n    q.getResultList();\n} catch (RuntimeException e) {\n    // log actual row count and names before rethrowing\n    throw new AssertionError(\"criteria query returned unexpected data: \" + e.getMessage(), e);\n}","preventionTips":["Always run cleanUpData() before seeding to make tests idempotent","Wrap seeding in QuarkusTransaction.requiringNew() so it commits before querying","Assert with descriptive messages including the actual size","Reset the test database between runs"],"tags":["jpa","mysql","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"}