{"record":{"id":"aff9a1e8b86b5fa8","repo":"hibernate/hibernate-orm","slug":"query-has-no-select-clause-and-no-root-entities","errorCode":null,"errorMessage":"query has no 'select' clause, and no root entities (every selection query must have an explicit 'select', an explicit 'from', or an explicit entity result type)","messagePattern":"query has no 'select' clause, and no root entities \\(every selection query must have an explicit 'select', an explicit 'from', or an explicit entity result type\\)","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":1274,"sourceCode":"\t\t\t//noinspection unchecked\n\t\t\treturn (EntityDomainType<R>) entityDescriptor;\n\t\t}\n\t\telse if ( expectedResultType != null ) {\n\t\t\tfinal var entityDescriptor = jpaMetamodel.findEntityType( expectedResultType );\n\t\t\tif ( entityDescriptor == null ) {\n\t\t\t\tthrow new SemanticException( \"Query has no 'from' clause, and the result type '\"\n\t\t\t\t\t\t+ expectedResultTypeShortName + \"' is not an entity type\", query );\n\t\t\t}\n\t\t\treturn entityDescriptor;\n\t\t}\n\t\telse {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tprotected SqmSelectClause buildInferredSelectClause(SqmFromClause fromClause) {\n\t\tif ( fromClause.getNumberOfRoots() == 0 ) {\n\t\t\tthrow new SemanticException( \"query has no 'select' clause, and no root entities\"\n\t\t\t\t\t+ \" (every selection query must have an explicit 'select', an explicit 'from', or an explicit entity result type)\",\n\t\t\t\t\tquery );\n\t\t}\n\n\t\tfinal var nodeBuilder = nodeBuilder();\n\t\tfor ( var sqmRoot : fromClause.getRoots() ) {\n\t\t\tif ( \"this\".equals( sqmRoot.getExplicitAlias() ) ) {\n\t\t\t\t// we found an entity with the alias 'this'\n\t\t\t\t// assigned explicitly, JPA says we should\n\t\t\t\t// infer the select list 'select this'\n\t\t\t\tfinal var selectClause =\n\t\t\t\t\t\tnew SqmSelectClause( false, 1, nodeBuilder );\n\t\t\t\tselectClause.addSelection( new SqmSelection<>( sqmRoot, \"this\", nodeBuilder) );\n\t\t\t\treturn selectClause;\n\t\t\t}\n\t\t}\n\n\t\tif ( expectedResultType == null ) {","sourceCodeStart":1256,"sourceCodeEnd":1292,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L1256-L1292","documentation":"Error \"query has no 'select' clause, and no root entities (every selection query must have an explicit 'select', an explicit 'from', or an explicit entity result type)\" thrown in hibernate/hibernate-orm.","triggerScenarios":"The HQL/JPQL query violates a structural language rule.","commonSituations":"Writing queries with missing select/from, mismatched group by positions, or invalid ordering constructs.","solutions":["Add an explicit 'select' or 'from' clause, or pass an entity result type to createQuery.","Rewrite the query with a clear 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"}