{"record":{"id":"63be8b3f1534765a","repo":"hibernate/hibernate-orm","slug":"query-has-no-from-clause-and-the-result-type-63be8b","errorCode":null,"errorMessage":"Query has no 'from' clause, and the result type '\" + expectedResultTypeShortName + \"' is not an entity type","messagePattern":"Query has no 'from' clause, and the result type '\" \\+ expectedResultTypeShortName \\+ \"' is not an entity type","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":1262,"sourceCode":"\t\t\treturn fromClause;\n\t\t}\n\t}\n\n\tprivate EntityDomainType<R> getResultEntity() {\n\t\tfinal var jpaMetamodel = creationContext.getJpaMetamodel();\n\t\tif ( expectedResultEntity != null ) {\n\t\t\tfinal var entityDescriptor = jpaMetamodel.findEntityType( expectedResultEntity );\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+ expectedResultEntity + \"' is not an entity type\", query );\n\t\t\t}\n\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() ) {","sourceCodeStart":1244,"sourceCodeEnd":1280,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L1244-L1280","documentation":"Error \"Query has no 'from' clause, and the result type '\" + expectedResultTypeShortName + \"' is not an entity 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 a 'from' clause to the query.","Ensure the expected result type is a mapped 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"}