hibernate/hibernate-orm · error · QueryException

Query root [%s] and result type [%s] are not compatible

Error message

Query root [%s] and result type [%s] are not compatible

What it means

Error "Query root [%s] and result type [%s] are not compatible" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/specification/internal/SelectionSpecificationImpl.java:427

			throw new QueryException( "Query defined multiple roots", hql );
		}

		final var sqmRoot = sqmRoots.iterator().next();
		return validateRoot( sqmRoot, resultType, hql );
		// for later, to support select lists
		//validateResultType( sqmStatement, sqmRoot, resultType, hql );
	}

	@Nonnull
	private SqmRoot<? extends T> validateRoot(
			@Nonnull SqmRoot<?> sqmRoot,
			@Nonnull Class<T> resultType,
			@Nonnull String hql) {
		final var javaType = sqmRoot.getJavaType();
		if ( javaType != null
				&& !Map.class.isAssignableFrom( javaType )
				&& !resultType.isAssignableFrom( javaType ) ) {
			throw new QueryException(
					String.format(
							Locale.ROOT,
							"Query root [%s] and result type [%s] are not compatible",
							javaType.getName(),
							resultType.getName()
					),
					hql
			);
		}
		else {
			@SuppressWarnings("unchecked") // Safe, we just checked
			final var castRoot = (SqmRoot<T>) sqmRoot;
			return castRoot;
		}
	}

//	/**
//	 * For future, allowing explicit select list.

View on GitHub (pinned to fad1729dce)

Solutions

  1. The query root type is not compatible with the requested result type. Align the root entity with the result type.

When it happens

Trigger: The requested result type does not match what the query produces: Query root [<value>] and result type [<value>] are not compatible

Common situations: Creating a typed query whose result class differs from the query root/select item type, or passing a result type for a non-select statement.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/a1daf30893004c98. Report an issue: GitHub.