{"record":{"id":"efdd472a33616e0e","repo":"hibernate/hibernate-orm","slug":"query-did-not-return-a-unique-result-resultco","errorCode":null,"errorMessage":"Query did not return a unique result: \" + resultCount + \" results were returned","messagePattern":"Query did not return a unique result: \" \\+ resultCount \\+ \" results were returned","errorType":"exception","errorClass":"NonUniqueResultException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/ResultListTransformer.java","lineNumber":68,"sourceCode":"\t * {@link NonUniqueResultException} otherwise.\n\t *\n\t * @param <T> The result list element type\n\t *\n\t * @since 7.3\n\t */\n\tstatic <T> ResultListTransformer<T> uniqueResultTransformer() {\n\t\treturn resultList ->\n\t\t\t\tswitch ( resultList.size() ) {\n\t\t\t\t\tcase 0, 1 -> resultList;\n\t\t\t\t\tdefault -> {\n\t\t\t\t\t\tfinal var first = resultList.get( 0 );\n\t\t\t\t\t\tfor ( int i = 1; i < resultList.size(); i++ ) {\n\t\t\t\t\t\t\tfinal T current = resultList.get( i );\n\t\t\t\t\t\t\tif ( !Objects.equals( first, current )\n\t\t\t\t\t\t\t\t\t// also consider case of multiple select items in an Object[]\n\t\t\t\t\t\t\t\t\t&& !( first instanceof Object[] array\n\t\t\t\t\t\t\t\t\t\t\t&& !Arrays.equals( array, (Object[]) current ) ) ) {\n\t\t\t\t\t\t\t\tthrow new NonUniqueResultException( resultList.size() );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tyield List.of( first );\n\t\t\t\t\t}\n\t\t\t\t};\n\t}\n}\n","sourceCodeStart":50,"sourceCodeEnd":76,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/ResultListTransformer.java#L50-L76","documentation":"Error \"Query did not return a unique result: \" + resultCount + \" results were returned\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A runtime precondition of the Hibernate API is violated.","commonSituations":"Occurs when application code or configuration does not satisfy the documented contract of the API being called.","solutions":["Add restricting criteria so the query returns at most one row.","Use getResultList() if multiple results are valid."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}