{"record":{"id":"22ffa85d3612758a","repo":"quarkusio/quarkus","slug":"incorrect-order-of-results-22ffa8","errorCode":null,"errorMessage":"Incorrect order of results","messagePattern":"Incorrect order 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":66,"sourceCode":"            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();\n\n            if (!singleResult.getName().equals(\"Quarkus\")) {\n                throw new RuntimeException(\"Wrong result from named JPA query\");","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java#L48-L84","documentation":"Postgres variant of the ordering assertion: the Criteria query with orderBy(name asc) did not return 'Gizmo' as the first element. Either the ORDER BY was not applied to the SQL sent to PostgreSQL or the data set differs from the seed expectations.","triggerScenarios":"Executing the ordered Criteria query in the jpa-postgresql base endpoint when the first Person row's name is not 'Gizmo' — missing ORDER BY in generated SQL, different seed names, or collation surprises.","commonSituations":"Locale/collation differences in the PostgreSQL instance, leftover rows with names alphabetically before 'Gizmo', or a Hibernate dialect/translation regression.","solutions":["Print allpersons names in returned order to diagnose","Enable Hibernate SQL logging to confirm ORDER BY name asc is present","Verify seed data names exactly match expectations","Check the column collation/ctype of the PostgreSQL database"],"exampleFix":"// before\nif (!allpersons.get(0).getName().equals(\"Gizmo\")) {\n    throw new RuntimeException(\"Incorrect order of results\");\n}\n// after (diagnostic)\nSystem.out.println(\"order: \" + allpersons.stream().map(Person::getName).toList());\nif (!allpersons.get(0).getName().equals(\"Gizmo\")) {\n    throw new RuntimeException(\"Incorrect order of results\");\n}","handlingStrategy":"validation","validationCode":"List<String> names = allpersons.stream().map(Person::getName).toList();\nif (!Objects.equals(names.stream().sorted().findFirst().orElse(null), \"Gizmo\")) {\n    throw new IllegalStateException(\"First row is not 'Gizmo': \" + names);\n}","typeGuard":null,"tryCatchPattern":"try {\n    q.getResultList();\n} catch (RuntimeException e) {\n    throw new AssertionError(\"ordered query failed: \" + e.getMessage(), e);\n}","preventionTips":["Assert on the full ordered name list, not just the first element","Confirm ORDER BY appears in logged SQL","Check PostgreSQL collation (LC_COLLATE) in the test container"],"tags":["jpa","postgresql","sorting","criteria-api"],"backgroundTag":"jpa-query-order-mismatch","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"}