hibernate/hibernate-orm · error · HibernateException

A native SQL query cannot use EntityGraphs

Error message

A native SQL query cannot use EntityGraphs

What it means

Error "A native SQL query cannot use EntityGraphs" thrown in hibernate/hibernate-orm.

Source

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

	@Nonnull
	public NativeQueryImplementor<R> asSelectionQuery() {
		errorIfNotSelectForSure();
		return this;
	}

	@Override
	@Nonnull
	public <X> NativeQueryImplementor<X> asSelectionQuery(Class<X> type) {
		errorIfNotSelectForSure();
		checkResultType( type, resultSetMapping() );
		//noinspection unchecked
		return (NativeQueryImplementor<X>) this;
	}

	@Override
	@Nonnull
	public <X> NativeQueryImplementor<X> asSelectionQuery(EntityGraph<X> entityGraph) {
		throw new HibernateException( "A native SQL query cannot use EntityGraphs" );
	}

	@Override
	@Nonnull
	public NativeQueryImplementor<R> asMutationQuery() {
		errorIfNotSelectForSure();
		return this;
	}

	private ParameterInterpretation resolveParameterInterpretation(
			String sqlString, SharedSessionContractImplementor session) {
		return getInterpretationCache( session )
				.resolveNativeQueryParameters( sqlString,
						s -> parameterInterpretation( sqlString ) );
	}

	private ParameterInterpretationImpl parameterInterpretation(String sqlString) {
		return ParameterInterpretationImpl.interpretParameters( sqlString, getSessionFactory() );

View on GitHub (pinned to fad1729dce)

Solutions

  1. EntityGraphs (fetchgraph/loadgraph hints) are not supported on native SQL queries.
  2. Remove the EntityGraph hint, or rewrite the query in HQL where EntityGraphs are supported.

When it happens

Trigger: An API operation is invoked on a query object that does not support it.

Common situations: Calling query hint, locking, pagination, conversion, or mutation APIs on a query kind (native vs HQL, select vs mutation) that does not implement them.


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