hibernate/hibernate-orm · error · IllegalStateException
MutationQuery cannot be treated as a SelectionQuery - {}
Error message
MutationQuery cannot be treated as a SelectionQuery - {} What it means
Error "MutationQuery cannot be treated as a SelectionQuery - {}" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/spi/MutationQueryImplementor.java:237
@Override
@Nonnull
<P> MutationQueryImplementor<T> setConvertedParameter(@Nonnull String name, @Nullable P value, @Nonnull Class<? extends AttributeConverter<P, ?>> converter);
@Override
@Nonnull
<P> MutationQueryImplementor<T> setConvertedParameter(int position, @Nullable P value, @Nonnull Class<? extends AttributeConverter<P, ?>> converter);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SelectionQuery stuff
@Override
@Deprecated
@SuppressWarnings("removal")
@Nullable
default LockModeType getLockMode() {
// IllegalStateException is the type required by JPA
throw new IllegalStateException( "MutationQuery cannot be treated as a SelectionQuery - " + getMutationString() );
}
@Override
@Deprecated
@SuppressWarnings("removal")
@Nonnull
default QueryImplementor<T> setLockMode(@Nonnull LockModeType lockMode) {
// IllegalStateException is the type required by JPA
throw new IllegalStateException( "MutationQuery cannot be treated as a SelectionQuery - " + getMutationString() );
}
@Override
@Deprecated
@SuppressWarnings("removal")
@Nonnull
default CacheStoreMode getCacheStoreMode() {
throw new IllegalStateException( "MutationQuery cannot be treated as a SelectionQuery - " + getMutationString() );
}View on GitHub (pinned to fad1729dce)
Solutions
- A MutationQuery cannot be used as a SelectionQuery. Use a select query to read results, or executeUpdate() for the mutation.
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/852fa59d753d20bf.
Report an issue: GitHub.