hibernate/hibernate-orm · error · SemanticException

Query has no 'select' clause, and joins, but no result type

Error message

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

What it means

Error "Query has no 'select' clause, and joins, 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:1312

				// a subquery ... the following is a bit arbitrary
				final var selectClause = new SqmSelectClause( false, nodeBuilder );
				fromClause.visitRoots( sqmRoot -> {
					selectClause.addSelection( new SqmSelection<>( sqmRoot, sqmRoot.getAlias(), nodeBuilder) );
					applyJoinsToInferredSelectClause( sqmRoot, selectClause );
				} );
				return selectClause;
			}
			else {
				// no result type was specified (and this isn't a subquery)
				// if there's a single root entity with no non-fetch joins,
				// we may safely assume the query returns that entity
				if ( fromClause.getNumberOfRoots() == 1 ) {
					final var sqmRoot = fromClause.getRoots().get(0);
					if ( sqmRoot.hasImplicitlySelectableJoin() ) {
						// the entity has joins, and doesn't explicitly have
						// 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 );
				}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Pass an explicit result type to createQuery (e.g. Object[].class).
  2. Add a 'select' clause naming the joined 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/708707d305d5a9ac. Report an issue: GitHub.