hibernate/hibernate-orm · error · UnsupportedOperationException

Fetch profiles not supported for ProcedureCall

Error message

Fetch profiles not supported for ProcedureCall

What it means

enableFetchProfile(profileName) activates a named fetch profile (declared via @FetchProfile) on a query. Fetch profiles alter association fetching during query translation, which never happens for a stored-procedure call; ProcedureCallImpl rejects the call with UnsupportedOperationException.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java:344

	@Nonnull
	public ProcedureCallImplementor<R> addQueryHint(@Nonnull String hint) {
		checkNotClosed();
		super.addQueryHint( hint );
		return this;
	}

	@Override @Deprecated
	@SuppressWarnings("removal")
	@Nonnull
	public Query<R> setEntityGraph(@Nonnull EntityGraph<? super R> graph, @Nonnull GraphSemantic semantic) {
		throw new UnsupportedOperationException( "Entity graph not supported for ProcedureCall" );
	}

	@Override @Deprecated
	@SuppressWarnings("removal")
	@Nonnull
	public Query<R> enableFetchProfile(@Nonnull String profileName) {
		throw new UnsupportedOperationException( "Fetch profiles not supported for ProcedureCall" );
	}

	@Override @Deprecated
	@SuppressWarnings("removal")
	@Nonnull
	public Query<R> disableFetchProfile(@Nonnull String profileName) {
		throw new UnsupportedOperationException( "Fetch profiles not supported for ProcedureCall" );
	}

	@Override
	public boolean isQueryPlanCacheable() {
		return false;
	}

	@Override
	@Nonnull
	public ProcedureCallImplementor<R> setQueryPlanCacheable(boolean queryPlanCacheable) {
		throw new UnsupportedOperationException( "Not supported" );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Restrict enableFetchProfile to SelectionQuery instances (instanceof guard).
  2. For procedures, have the procedure return the extra data and map it with an explicit SqlResultSetMapping.

Example fix

// before
query.enableFetchProfile("order.with-lines"); // query is a ProcedureCall -> throws

// after
if (query instanceof org.hibernate.query.SelectionQuery<?> sq) {
    sq.enableFetchProfile("order.with-lines");
}
Defensive patterns

Strategy: type-guard

Type guard

static boolean supportsFetchProfile(jakarta.persistence.Query q) {
    return q instanceof org.hibernate.query.SelectionQuery;
}

Try / catch

try {
    q.enableFetchProfile( profileName );
} catch (UnsupportedOperationException e) {
    // procedure call: fetch profiles only affect translated HQL/Criteria queries
}

Prevention

When it happens

Trigger: Calling enableFetchProfile("order.with-lines") on a ProcedureCall/StoredProcedureQuery — commonly from generic optimization code that enables a profile on every query in a service method.

Common situations: Codebases with global fetch-profile strategies applied to all queries; profiling/performance tooling that toggles profiles around query execution.

Related errors


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