hibernate/hibernate-orm · error · IllegalStateException

Named query (%s) was not a native-query

Error message

Named query (%s) was not a native-query

What it means

Error "Named query (%s) was not a native-query" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java:2900

		eventListenerGroups = getFactory().getEventListenerGroups();
	}

	// Used by Hibernate reactive
	protected Boolean getReadOnlyFromLoadQueryInfluencers() {
		return loadQueryInfluencers.getReadOnly();
	}

	@Override @Deprecated
	@SuppressWarnings({"rawtypes", "removal"})
	@Nonnull
	public NativeQueryImplementor getNamedNativeQuery(@Nonnull String name) {
		final var query = createNamedQuery( name );
		if ( query instanceof NativeQueryImplementor nativeQueryImplementor ) {
			return nativeQueryImplementor;
		}
		else {
			throw new IllegalStateException( String.format( Locale.ROOT,
					"Named query (%s) was not a native-query",
					name
			) );
		}
	}
}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Use createNativeQuery with a named native query (@NamedNativeQuery), or use createNamedQuery for HQL/JPQL named queries.
  2. Verify the named query type matches the API you are calling.

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java:2900 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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