hibernate/hibernate-orm · error · IllegalArgumentException

Requested tuple element did not correspond to element in the

Error message

Requested tuple element did not correspond to element in the result tuple

What it means

Thrown by TupleImpl.get(TupleElement) when the passed TupleElement is not registered in this tuple's TupleMetadata. TupleElement handles are only meaningful for the query that produced them; each execution builds its own metadata keyed by alias. The check is an identity/lookup failure, not a type failure - the element simply does not belong to this result tuple.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/sql/results/internal/TupleImpl.java:35

/**
 * Implementation of the JPA Tuple contract
 *
 * @author Steve Ebersole
 */
public class TupleImpl implements Tuple {
	private final TupleMetadata tupleMetadata;
	private final Object[] row;

	public TupleImpl(TupleMetadata tupleMetadata, Object[] row) {
		this.tupleMetadata = tupleMetadata;
		this.row = row;
	}

	@Override
	public <X> X get(TupleElement<X> tupleElement) {
		final Integer index = tupleMetadata.get( tupleElement );
		if ( index == null ) {
			throw new IllegalArgumentException(
					"Requested tuple element did not correspond to element in the result tuple"
			);
		}
		// index should be "in range" by nature of size check in ctor
		return cast( tupleElement.getJavaType(), row[index] );
	}

	@Override
	public <X> X get(String alias, Class<X> type) {
		final Object untyped = get( alias );
		if ( untyped != null ) {
			if ( !isInstance( type, untyped ) ) {
				throw new IllegalArgumentException(
						String.format(
								"Requested tuple value [alias=%s, value=%s] cannot be assigned to requested type [%s]",
								alias,
								untyped,
								type.getName()

View on GitHub (pinned to fad1729dce)

Solutions

  1. Get values by alias or index instead: `tuple.get("id", Long.class)` or `tuple.get(0)`
  2. Only use TupleElement handles obtained from that same tuple: `tuple.getElements().get(i)`
  3. Pass aliases (String) between components rather than TupleElement objects

Example fix

// before
X v = someTuple.get(elementFromEarlierQuery);
// after
X v = someTuple.get(elementFromEarlierQuery.getAlias(), (Class<X>) elementFromEarlierQuery.getJavaType());
Defensive patterns

Strategy: validation

Validate before calling

// Only use element handles that belong to this tuple
boolean known = tuple.getElements().stream()
        .anyMatch(el -> el.getAlias().equals(element.getAlias())
                && el.getJavaType() == element.getJavaType());
if (!known) { /* fall back to alias lookup */ }

Prevention

When it happens

Trigger: Caching a TupleElement from query A and calling `tupleFromB.get(cachedElement)`; implementing a custom TupleElement and passing it in; comparing elements across two executions of the same query whose aliases differ (e.g. generated alias changes).

Common situations: Helper utilities that accept `(Tuple, TupleElement)` pairs assembled from different sources; refactoring that separates tuple creation from element definition; tests that mock Tuple/TupleElement inconsistently.

Related errors


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