hibernate/hibernate-orm · error · SemanticException
Query has no 'from' clause, and the result type '" + expecte
Error message
Query has no 'from' clause, and the result type '" + expectedResultEntity + "' is not an entity type
What it means
Error "Query has no 'from' clause, and the result type '" + expectedResultEntity + "' is not an entity type" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:1253
final var fromClause = new SqmFromClause();
final var entityDescriptor = getResultEntity();
if ( entityDescriptor != null ) {
final SqmRoot<R> sqmRoot =
new SqmRoot<>( entityDescriptor, "_0", false, nodeBuilder() );
processingStateStack.getCurrent().getPathRegistry().register( sqmRoot );
fromClause.addRoot( sqmRoot );
}
return fromClause;
}
}
private EntityDomainType<R> getResultEntity() {
final var jpaMetamodel = creationContext.getJpaMetamodel();
if ( expectedResultEntity != null ) {
final var entityDescriptor = jpaMetamodel.findEntityType( expectedResultEntity );
if ( entityDescriptor == null ) {
throw new SemanticException( "Query has no 'from' clause, and the result type '"
+ expectedResultEntity + "' is not an entity type", query );
}
//noinspection unchecked
return (EntityDomainType<R>) entityDescriptor;
}
else if ( expectedResultType != null ) {
final var entityDescriptor = jpaMetamodel.findEntityType( expectedResultType );
if ( entityDescriptor == null ) {
throw new SemanticException( "Query has no 'from' clause, and the result type '"
+ expectedResultTypeShortName + "' is not an entity type", query );
}
return entityDescriptor;
}
else {
return null;
}
}
View on GitHub (pinned to fad1729dce)
Solutions
- Add a 'from' clause selecting the entity.
- Pass the correct entity result type to createQuery.
When it happens
Trigger: The HQL/JPQL query violates a structural language rule.
Common situations: Writing queries with missing select/from, mismatched group by positions, or invalid ordering constructs.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/99e6108dcf42b4a5.
Report an issue: GitHub.