hibernate/hibernate-orm · error · IllegalArgumentException

Could not create StatementReference from given Statement

Error message

Could not create StatementReference from given Statement - {}

What it means

Wrapping failure in registerNamedMutation: the given Statement could not be unwrapped to a StatementReferenceProducer, so no mutation memento could be created from it.

Solutions

  1. A StatementReference could not be built from the given statement. Supply a valid named statement reference.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: A named-query reference cannot be built from the given object: Could not create StatementReference from given Statement - <value>

Common situations: Registering named queries from objects that are not proper TypedQuery/Statement instances.


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/query/named/internal/NamedObjectRepositoryImpl.java:159

	}

	@Override
	@Nonnull
	public Map<String, StatementReference> getNamedMutations() {
		return Collections.unmodifiableMap( mutationMementos );
	}

	@Override
	@Nonnull
	public StatementReference registerNamedMutation(@Nonnull String name, @Nonnull Statement statement) {
		try {
			final var refProducer = statement.unwrap( StatementReferenceProducer.class );
			final var ref = refProducer.toMutationMemento( name );
			mutationMementos.put( name, ref );
			return ref;
		}
		catch (Exception e) {
			throw new IllegalArgumentException( "Could not create StatementReference from given Statement - " + statement, e );
		}
	}

	@Override
	public void forEachNamedMutation(@Nonnull BiConsumer<String,? super StatementReference> action) {
		mutationMementos.forEach( action );
	}

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// callable mementos

	@Override
	@Nullable
	public NamedCallableQueryMemento getCallableQueryMemento(@Nonnull String name) {
		return callableMementoMap.get( name );
	}

	@Override

View on GitHub (pinned to fad1729dce)