hibernate/hibernate-orm · error · SemanticException

Query has no 'select' clause, and multiple root entities, bu

Error message

Query has no 'select' clause, and multiple root entities, but no result type was given (pass an explicit result type to 'createQuery()')

What it means

Error "Query has no 'select' clause, and multiple root entities, but no result type was given (pass an explicit result type to 'createQuery()')" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:1328

						// the alias 'this', so the 'select' list cannot be
						// inferred
						throw new SemanticException( "Query has no 'select' clause, and joins, but no result type was given"
								+ " (pass an explicit result type to 'createQuery()')", query );
					}
					// exactly one root entity, and no joins - this includes
					// the case where JPA says the entity has an implicit alias
					// 'this', and that we should infer 'select this', but we
					// accept even the case where the entity has an explicit
					// alias, and infer 'select explicit_alias'
					final var selectClause =
							new SqmSelectClause( false, 1, nodeBuilder );
					selectClause.addSelection( new SqmSelection<>( sqmRoot, sqmRoot.getAlias(), nodeBuilder) );
					return selectClause;
				}
				else {
					// there's more than one entity, and no entity is 'this',
					// therefore the 'select' list cannot be inferred
					throw new SemanticException( "Query has no 'select' clause, and multiple root entities, but no result type was given"
							+ " (pass an explicit result type to 'createQuery()')", query );
				}
			}
		}
		else {
			// we have an explicit result type, so we can use that to
			// help infer the 'select' list
			if ( creationContext.getJpaMetamodel().findEntityType( expectedResultType ) != null ) {
				// the result type is an entity class
				if ( fromClause.getNumberOfRoots() > 1 ) {
					// multiple root entities
					throw new SemanticException( "Query has no 'select' clause, and multiple root entities, but query result type is an entity class"
							+ " (specify an explicit 'select' list, or a different result type, for example, 'Object[].class')",
							query );
				}
				else {
					final var sqmRoot = fromClause.getRoots().get(0);
					if ( sqmRoot instanceof SqmCteRoot ) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Pass Object[].class (or another explicit result type) to createQuery.
  2. Add an explicit 'select' list choosing the needed roots.

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/2ea6a314c07a0264. Report an issue: GitHub.