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
- Add explicit aliases in the select list: `select sum(e.salary) as total ...` then `tuple.get("total")`
- Discover the real available aliases once via `tuple.getElements()` and use those names
- 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
- Always alias every selected expression in queries whose results are read as Tuple
- Use tuple.getElements() during development to discover generated alias names
- Read by index when aliases are unstable, or by alias when they are explicit
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
- Requested tuple element did not correspond to element in the
- Selection item in a multi-select cannot contain compound tup
- Entity join treats can not be aliased
- Requested tuple value [alias=%s, value=%s] cannot be assigne
- Requested tuple value [index=%s, realType=%s] cannot be assi
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/57cab85102664175.
Report an issue: GitHub.