hibernate/hibernate-orm · error · IllegalSelectQueryException

Not a NamedSelectionMemento

Error message

Not a NamedSelectionMemento

What it means

IllegalSelectQueryException guard: toSelectionQuery was called on a criteria-based mutation memento; its statement is an insert/update/delete and cannot be executed as a selection query.

Solutions

  1. The memento is not a NamedSelectionMemento. Use a named select query where a selection memento is required.
Defensive patterns

Strategy: validation

When it happens

Trigger: A named query memento is used as the wrong query kind: Not a NamedSelectionMemento

Common situations: Internal mix-up reusing a named selection memento as a mutation memento or vice versa (e.g. via getNamedQuery APIs).


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/query/named/internal/CriteriaMutationMementoImpl.java:105

		return new MutationQueryImpl( this, mutationAst, session );
	}

	@Nonnull
	@Override
	public QueryImplementor<T> toQuery(@Nonnull SharedSessionContractImplementor session) {
		return toMutationQuery( session, queryType );
	}

	@Nonnull
	@Override
	public <X> QueryImplementor<X> toQuery(@Nonnull SharedSessionContractImplementor session, @Nullable Class<X> javaType) {
		return toMutationQuery( session, javaType );
	}

	@Nonnull
	@Override
	public SelectionQueryImplementor<T> toSelectionQuery(@Nonnull SharedSessionContractImplementor session) {
		throw new IllegalSelectQueryException( "Not a NamedSelectionMemento", getHqlString() );
	}

	@Nonnull
	@Override
	public <X> SelectionQueryImplementor<X> toSelectionQuery(@Nonnull SharedSessionContractImplementor session, @Nullable Class<X> javaType) {
		throw new IllegalSelectQueryException( "Not a NamedSelectionMemento", getHqlString() );
	}
}

View on GitHub (pinned to fad1729dce)