hibernate/hibernate-orm · error · IllegalArgumentException

Error applying query hint

Error message

Error applying query hint '%s': %s

What it means

Wrapping failure from setHint: applying a recognized query hint threw an unexpected (non-IAE/ISE) exception, which is rethrown as IllegalArgumentException with the hint name and cause.

Solutions

  1. Applying the query hint failed. Verify the hint name is supported and its value has the expected type/format for that hint.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: An invalid or inapplicable query hint is set: Error applying query hint '<value>': <value>

Common situations: Passing wrong-typed hint values, entity-graph hints that are neither named graphs nor parseable GraphParser strings, ProcedureCall-only hints on normal queries, or query-spaces hints on non-native queries.


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/query/internal/AbstractCommonQueryContract.java:444

	protected void putIfNotNull(Map<String, Object> hints, String hintName, Object hintValue) {
		if ( hintValue != null ) {
			hints.put( hintName, hintValue );
		}
	}

	@Override
	@Nonnull
	public CommonQueryContractImplementor setHint(@Nonnull String hintName, @Nullable Object value) {
		try {
			if ( !applyHint( hintName, value ) ) {
				QUERY_MESSAGE_LOGGER.ignoringUnrecognizedQueryHint( hintName );
			}
		}
		catch (IllegalArgumentException|IllegalStateException jpaExpected) {
			throw jpaExpected;
		}
		catch (Exception e) {
			throw new IllegalArgumentException(
					"Error applying query hint '%s': %s"
							.formatted( hintName, e.getMessage() ),
					e
			);
		}
		return this;
	}

	/**
	 * This method takes responsibility to recognize all known hints
	 * and collecting the values.
	 * <p>
	 * However, not all hints are valid for all types of queries which
	 * is beyond the understanding of this context.
	 * <p>
	 * Hints which are always relevant are handled by directly applying
	 * the corresponding option.  These include:<ul>
	 *     <li>{@linkplain QueryOptions#getQueryFlushMode() flush mode}

View on GitHub (pinned to fad1729dce)