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 '" + expectedResultTypeShortName + "' is not an entity type

What it means

Error "Query has no 'from' clause, and the result type '" + expectedResultTypeShortName + "' 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: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)

Solutions

  1. Add a 'from' clause to the query.
  2. Ensure the expected result type is a mapped entity.

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.