hibernate/hibernate-orm · error · SemanticException
Could not resolve alias
Error message
Could not resolve alias '${alias}' in selection [${selection}] What it means
Thrown while resolving a select-item alias in SemanticQueryBuilder: an 'order by'/'group by' entry or selection refers to an alias that is not registered in the current processing state's path registry. The offending inputs are the unresolvable alias and the selection text referencing it; the guard fires when the alias was never declared in the query.
Solutions
- Alias the selection explicitly and reference that exact alias.
- Check alias spelling in the order/group-by clause.
Defensive patterns
Strategy: validation
When it happens
Trigger: A name referenced in a mapping, query, or configuration cannot be resolved at runtime.
Common situations: Typos in entity/attribute/mapping names, missing mappings, or refactoring without updating references.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/b3bf98d60ebbb725.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:1593
: visitPluralCollectionFunctionSelection( expressionOrPredicate );
final var argExpression = collectionFunctionSelection == null
? pluralPathSelection( (SqmSelectableNode<?>) ctx.instantiationArgumentExpression().accept( this ) )
: collectionFunctionSelection;
final var argument = new SqmDynamicInstantiationArgument<>( argExpression, alias, nodeBuilder() );
if ( !(argExpression instanceof SqmDynamicInstantiation) ) {
processingStateStack.getCurrent().getPathRegistry().register( argument );
}
return argument;
}
@Override
public SqmPath<?> visitJpaSelectObjectSyntax(HqlParser.JpaSelectObjectSyntaxContext ctx) {
final var alias = ctx.getChild( 2 ).getText();
final var sqmFromByAlias =
processingStateStack.getCurrent().getPathRegistry()
.findFromByAlias( alias, true );
if ( sqmFromByAlias == null ) {
throw new SemanticException( "Could not resolve alias '" + alias
+ "' in selection [" + ctx.getText() + "]",
query );
}
return sqmFromByAlias;
}
@Override
public List<SqmExpression<?>> visitGroupByClause(HqlParser.GroupByClauseContext ctx) {
final var groupByExpressionContexts = ctx.groupByExpression();
final int size = groupByExpressionContexts.size();
final List<SqmExpression<?>> expressions = new ArrayList<>( size );
for ( int i = 0; i < size; i++ ) {
expressions.add( (SqmExpression<?>) groupByExpressionContexts.get( i ).accept( this ) );
}
return expressions;
}
private SqmExpression<?> resolveOrderByOrGroupByExpression(View on GitHub (pinned to fad1729dce)