{"record":{"id":"27b028ea50c3a3d5","repo":"hibernate/hibernate-orm","slug":"query-did-not-define-any-roots","errorCode":null,"errorMessage":"Query did not define any roots","messagePattern":"Query did not define any roots","errorType":"exception","errorClass":"QueryException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/specification/internal/SelectionSpecificationImpl.java","lineNumber":406,"sourceCode":"\t\t\tthrow new IllegalSelectQueryException(\n\t\t\t\t\t\"SelectionSpecification only supports HQL or criteria query references: \"\n\t\t\t\t\t\t\t+ typedQueryReference.getName()\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Used during construction. Mainly used to group extracting and\n\t * validating the root.\n\t */\n\t@Nonnull\n\tprivate SqmRoot<? extends T> extractRoot(\n\t\t\t@Nonnull SqmSelectStatement<T> sqmStatement,\n\t\t\t@Nonnull Class<T> resultType,\n\t\t\t@Nonnull String hql) {\n\t\tfinal var sqmRoots = sqmStatement.getQuerySpec().getRoots();\n\t\tif ( sqmRoots.isEmpty() ) {\n\t\t\tthrow new QueryException( \"Query did not define any roots\", hql );\n\t\t}\n\t\tif ( sqmRoots.size() > 1 ) {\n\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","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/specification/internal/SelectionSpecificationImpl.java#L388-L424","documentation":"Error \"Query did not define any roots\" thrown in hibernate/hibernate-orm.","triggerScenarios":"The query structure does not meet the single-root/single-select-item requirement: Query did not define any roots","commonSituations":"Key-based pagination or Specifications applied to queries with zero/multiple roots or multi-item select lists.","solutions":["The query defined no roots. Add a from-clause root entity."],"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"}