hibernate/hibernate-orm · error · SemanticException
Query has no 'from' clause, and the result type '" +…
Error message
Query has no 'from' clause, and the result type '" + expectedResultTypeShortName + "' is not an entity type
What it means
Thrown by SemanticQueryBuilder.getResultEntity when a from-less query was given an expected result type, but that class is not resolvable as an entity in the JPA metamodel, so no root entity can be inferred for the query. The offending input is the result type passed to createQuery(); the fix is to add an explicit 'from' clause or pass an entity class.
Solutions
- Add a 'from' clause to the query.
- Ensure the expected result type is a mapped entity.
Defensive patterns
Strategy: validation
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/63be8b3f1534765a.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:1262
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;
}
}
protected SqmSelectClause buildInferredSelectClause(SqmFromClause fromClause) {
if ( fromClause.getNumberOfRoots() == 0 ) {
throw new SemanticException( "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)",
query );
}
final var nodeBuilder = nodeBuilder();
for ( var sqmRoot : fromClause.getRoots() ) {View on GitHub (pinned to fad1729dce)