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 '" + expectedResultEntity + "' is not an entity type
What it means
Thrown by SemanticQueryBuilder.getResultEntity when a query has no 'from' clause and Hibernate tries to infer the root from the expected result type, but the supplied result type passed to createQuery() does not correspond to a known entity type. Without a from clause and without an entity result type there is no way to derive query roots; the offending input is the non-entity result class.
Solutions
- Add a 'from' clause selecting the entity.
- Pass the correct entity result type to createQuery.
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/99e6108dcf42b4a5.
Report an issue: GitHub.
Appendix: 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)