hibernate/hibernate-orm · error · IllegalStateException

Unsure how to create named query memento for native query -

Error message

Unsure how to create named query memento for native query - ${query}

What it means

Error "Unsure how to create named query memento for native query - ${query}" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java:521

			// as a last resort, see if the SQL starts with "select"
			|| startsWithSelect() ) {
			return true;
		}
		else {
			return null;
		}
	}

	@Override
	public NamedNativeQueryMemento<R> toMemento(String name) {
		if ( isSelectQuery() == Boolean.TRUE ) {
			return toSelectionMemento( name );
		}
		else if ( isSelectQuery() == Boolean.FALSE ) {
			return toMutationMemento( name );
		}
		else {
			throw new IllegalStateException( "Unsure how to create named query memento for native query - " + this );
		}
	}

	@Override
	public NativeMutationMementoImpl<R> toMutationMemento(String name) {
		errorIfSelectForSure();
		final var options = getQueryOptions();
		return new NativeMutationMementoImpl<>(
				name,
				originalSqlString,
				null,
				options.getQueryFlushMode(),
				options.getTimeout(),
				getComment(),
				getHints(),
				querySpaces
		);
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. The query being converted to a named-query memento is not a supported native query shape; only memento-able native queries can be registered as named queries.
  2. Define the named query via @NamedNativeQuery or orm.xml instead of converting an ad-hoc query.

When it happens

Trigger: A runtime precondition of the Hibernate query API is violated.

Common situations: Occurs when application code or configuration does not satisfy the documented contract of the API being called.


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