{"record":{"id":"99e6108dcf42b4a5","repo":"hibernate/hibernate-orm","slug":"query-has-no-from-clause-and-the-result-type","errorCode":null,"errorMessage":"Query has no 'from' clause, and the result type '\" + expectedResultEntity + \"' is not an entity type","messagePattern":"Query has no 'from' clause, and the result type '\" \\+ expectedResultEntity \\+ \"' 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":1253,"sourceCode":"\n\t\t\tfinal var fromClause = new SqmFromClause();\n\t\t\tfinal var entityDescriptor = getResultEntity();\n\t\t\tif ( entityDescriptor != null ) {\n\t\t\t\tfinal SqmRoot<R> sqmRoot =\n\t\t\t\t\t\tnew SqmRoot<>( entityDescriptor, \"_0\", false, nodeBuilder() );\n\t\t\t\tprocessingStateStack.getCurrent().getPathRegistry().register( sqmRoot );\n\t\t\t\tfromClause.addRoot( sqmRoot );\n\t\t\t}\n\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","sourceCodeStart":1235,"sourceCodeEnd":1271,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L1235-L1271","documentation":"Error \"Query has no 'from' clause, and the result type '\" + expectedResultEntity + \"' 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 selecting the entity.","Pass the correct entity result type to createQuery."],"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"}