hibernate/hibernate-orm · error · IllegalArgumentException

Given alias [{}] did not correspond to an element in the res

Error message

Given alias [{}] did not correspond to an element in the result tuple

What it means

Thrown by TupleImpl.get(String alias): no selection in this result tuple is registered under that alias. Aliases come from the query's select list; expressions selected without an explicit alias get Hibernate-generated aliases (typically positional strings like "0", "1"), so hand-guessed names for unaliased columns miss.

Source

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

			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()
						)
				);
			}
		}
		return cast( type, untyped );
	}

	@Override
	public Object get(String alias) {
		final Integer index = tupleMetadata.get( alias );
		if ( index == null ) {
			throw new IllegalArgumentException(
					"Given alias [" + alias + "] did not correspond to an element in the result tuple"
			);
		}
		// index should be "in range" by nature of size check in ctor
		return row[index];
	}

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

View on GitHub (pinned to fad1729dce)

Solutions

  1. Add explicit aliases in the select list: `select sum(e.salary) as total ...` then `tuple.get("total")`
  2. Discover the real available aliases once via `tuple.getElements()` and use those names
  3. For positional access use `tuple.get(0)`

Example fix

// before
select sum(e.salary) from Employee e  ...  tuple.get("total")
// after
select sum(e.salary) as total from Employee e  ...  tuple.get("total")
Defensive patterns

Strategy: validation

Validate before calling

// Validate the alias against this tuple's real element names before reading
Set<String> names = tuple.getElements().stream().map(TupleElement::getAlias).collect(java.util.stream.Collectors.toSet());
if (!names.contains(wantedAlias)) { /* log available names, use generated positional alias or fix query */ }

Prevention

When it happens

Trigger: `tuple.get("total")` when the query says `select sum(e.salary) from Employee e` with no `as total`; alias typo or case difference from the query text; querying by an alias that only exists in a different query variant.

Common situations: Reading tuple results from queries whose select list changed; unaliased native/HQL selections where the developer assumed the column name would be the alias; copy-pasting tuple-reading code between similar queries.

Related errors


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