hibernate/hibernate-orm · error · QueryTypeMismatchException

Incorrect query result type: query produces '%s' but type '%

Error message

Incorrect query result type: query produces '%s' but type '%s' was given

What it means

Error "Incorrect query result type: query produces '%s' but type '%s' was given" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/named/internal/CriteriaSelectionMementoImpl.java:143

	@Nonnull
	@Override
	public <T> SelectionQueryImplementor<T> toSelectionQuery(@Nonnull SharedSessionContractImplementor session, @Nullable Class<T> javaType) {
		checkResultType( javaType, selectAst );
		//noinspection rawtypes,unchecked
		return new SelectionQueryImpl( this, selectAst, javaType, session );
	}

	private static <T> void checkResultType(
			@Nullable Class<T> resultType,
			@Nonnull SqmSelectStatement<?> selectStatement) {
		if ( resultType == null ) {
			return;
		}
		final Class<?> expectedResultType = selectStatement.getResultType();
		if ( expectedResultType != Object.class
			&& !resultType.isAssignableFrom( expectedResultType ) ) {
			throw new QueryTypeMismatchException(
					String.format(
							Locale.ROOT,
							"Incorrect query result type: query produces '%s' but type '%s' was given",
							expectedResultType.getName(),
							resultType.getName()
					)
			);
		}
	}

}

View on GitHub (pinned to fad1729dce)

Solutions

  1. The query's actual result type differs from the requested type. Pass the correct result class, or adjust the query's select list.

When it happens

Trigger: The requested result type does not match what the query produces: Incorrect query result type: query produces '<value>' but type '<value>' was given

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/9d8d6494447243d4. Report an issue: GitHub.