{"record":{"id":"a1daf30893004c98","repo":"hibernate/hibernate-orm","slug":"query-root-s-and-result-type-s-are-not-compa","errorCode":null,"errorMessage":"Query root [%s] and result type [%s] are not compatible","messagePattern":"Query root \\[(.+?)\\] and result type \\[(.+?)\\] are not compatible","errorType":"exception","errorClass":"QueryException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/specification/internal/SelectionSpecificationImpl.java","lineNumber":427,"sourceCode":"\t\t\tthrow new QueryException( \"Query defined multiple roots\", hql );\n\t\t}\n\n\t\tfinal var sqmRoot = sqmRoots.iterator().next();\n\t\treturn validateRoot( sqmRoot, resultType, hql );\n\t\t// for later, to support select lists\n\t\t//validateResultType( sqmStatement, sqmRoot, resultType, hql );\n\t}\n\n\t@Nonnull\n\tprivate SqmRoot<? extends T> validateRoot(\n\t\t\t@Nonnull SqmRoot<?> sqmRoot,\n\t\t\t@Nonnull Class<T> resultType,\n\t\t\t@Nonnull String hql) {\n\t\tfinal var javaType = sqmRoot.getJavaType();\n\t\tif ( javaType != null\n\t\t\t\t&& !Map.class.isAssignableFrom( javaType )\n\t\t\t\t&& !resultType.isAssignableFrom( javaType ) ) {\n\t\t\tthrow new QueryException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\t\"Query root [%s] and result type [%s] are not compatible\",\n\t\t\t\t\t\t\tjavaType.getName(),\n\t\t\t\t\t\t\tresultType.getName()\n\t\t\t\t\t),\n\t\t\t\t\thql\n\t\t\t);\n\t\t}\n\t\telse {\n\t\t\t@SuppressWarnings(\"unchecked\") // Safe, we just checked\n\t\t\tfinal var castRoot = (SqmRoot<T>) sqmRoot;\n\t\t\treturn castRoot;\n\t\t}\n\t}\n\n//\t/**\n//\t * For future, allowing explicit select list.","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/specification/internal/SelectionSpecificationImpl.java#L409-L445","documentation":"Error \"Query root [%s] and result type [%s] are not compatible\" thrown in hibernate/hibernate-orm.","triggerScenarios":"The requested result type does not match what the query produces: Query root [<value>] and result type [<value>] are not compatible","commonSituations":"Creating a typed query whose result class differs from the query root/select item type, or passing a result type for a non-select statement.","solutions":["The query root type is not compatible with the requested result type. Align the root entity with the result type."],"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"}