improve error when a select item is missing its required alias

This commit is contained in:
Gavin 2023-05-28 10:11:49 +02:00 committed by Gavin King
parent 23b55db51a
commit a6f036d320
1 changed files with 3 additions and 1 deletions

View File

@ -22,6 +22,7 @@ import org.hibernate.metamodel.model.domain.SimpleDomainType;
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
import org.hibernate.metamodel.model.domain.TupleType;
import org.hibernate.query.ReturnableType;
import org.hibernate.query.SemanticException;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.tree.domain.SqmPath;
@ -58,7 +59,8 @@ public class AnonymousTupleType<T> implements TupleType<T>, DomainType<T>, Retur
final SqmSelectableNode<?> component = components[i];
final String alias = component.getAlias();
if ( alias == null ) {
throw new IllegalArgumentException( "Component at index " + i + " has no alias, but alias is required" );
throw new SemanticException( "Select item at position " + (i+1) + " in select list has no alias"
+ " (aliases are required in CTEs and in subqueries occurring in from clause)" );
}
map.put( alias, i );
}