{"record":{"id":"45559f8b71a9d419","repo":"quarkusio/quarkus","slug":"incorrect-number-of-results-45559f","errorCode":null,"errorMessage":"Incorrect number of results","messagePattern":"Incorrect number of results","errorType":"http","errorClass":"RuntimeException","httpStatus":500,"severity":"error","filePath":"integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/JPAFunctionalityTestEndpoint.java","lineNumber":56,"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":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/JPAFunctionalityTestEndpoint.java#L38-L74","documentation":"The endpoint seeds three Person rows, runs a CriteriaQuery ordered by name, and asserts exactly 3 results; a different count throws this RuntimeException. It detects leftover rows from prior runs, failed cleanup, or inserts that did not commit.","triggerScenarios":"GET the endpoint when the Person table contains fewer or more than 3 rows at query time — duplicate seeds without cleanup, other tests inserting Persons concurrently, or seed inserts failing silently.","commonSituations":"Test DB shared/persistent across runs accumulating rows; cleanUpData not invoked or failing; concurrent test executions against the same MSSQL instance; container reused with stale data.","solutions":["Ensure cleanUpData() runs before seeding at the start of each request/test","Reset the database/container between test runs (fresh testcontainer or drop/recreate schema)","Avoid running tests in parallel against a shared database","Add a unique constraint or delete-by-name cleanup to make seeding idempotent"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"long count = (long) em.createQuery(\"select count(p) from Person p\").getSingleResult();\nif (count != 0) { em.createQuery(\"delete from Person\").executeUpdate(); }  // clean before seeding","typeGuard":null,"tryCatchPattern":"try {\n    List<Person> all = q.getResultList();\n} catch (RuntimeException e) {\n    // log actual rows: allpersons.forEach(p -> System.out.println(p.getName()));\n}","preventionTips":["Always clean the table before seeding in tests","Use fresh testcontainers per run instead of a persistent DB","Disable parallel execution against shared databases","Assert actual row contents in failure messages for debuggability"],"tags":["jpa","criteria-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"}