hibernate/hibernate-orm · error · IllegalStateException

MutationQuery cannot be treated as a SelectionQuery - ${muta

Error message

MutationQuery cannot be treated as a SelectionQuery - ${mutationString}

What it means

Error "MutationQuery cannot be treated as a SelectionQuery - ${mutationString}" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/spi/MutationQueryImplementor.java:287

	@Nonnull
	default CacheRetrieveMode getCacheRetrieveMode() {
		throw new IllegalStateException( "MutationQuery cannot be treated as a SelectionQuery - " + getMutationString() );
	}

	@Override
	@Deprecated
	@SuppressWarnings("removal")
	@Nonnull
	default QueryImplementor<T> setCacheRetrieveMode(@Nonnull CacheRetrieveMode cacheRetrieveMode) {
		// IllegalStateException is the type required by JPA
		throw new IllegalStateException( "MutationQuery cannot be treated as a SelectionQuery - " + getMutationString() );
	}

	@Override
	@Deprecated
	@SuppressWarnings("removal")
	default int getMaxResults() {
		throw new IllegalStateException( "MutationQuery cannot be treated as a SelectionQuery - " + getMutationString() );
	}

	@Override
	@Deprecated
	@SuppressWarnings("removal")
	@Nonnull
	default QueryImplementor<T> setMaxResults(int maxResults) {
		// IllegalStateException is the type required by JPA
		throw new IllegalStateException( "MutationQuery cannot be treated as a SelectionQuery - " + getMutationString() );
	}

	@Override
	@Deprecated
	@SuppressWarnings("removal")
	default int getFirstResult() {
		throw new IllegalStateException( "MutationQuery cannot be treated as a SelectionQuery - " + getMutationString() );
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. A MutationQuery cannot be used as a SelectionQuery for the given statement. Use a selection query instead.

When it happens

Trigger: A selection-only operation is invoked on a mutation (insert/update/delete) query: MutationQuery cannot be treated as a SelectionQuery - $<value>

Common situations: Calling getResultList()/scroll()/unwrap(SelectionQuery) on a Query created from an update/delete/insert HQL statement, or vice versa.


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