From a6f036d3201df80aad440578505f4a461caa07f2 Mon Sep 17 00:00:00 2001 From: Gavin Date: Sun, 28 May 2023 10:11:49 +0200 Subject: [PATCH] improve error when a select item is missing its required alias --- .../java/org/hibernate/query/derived/AnonymousTupleType.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleType.java b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleType.java index 7e45f620a8..99612f43bf 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleType.java +++ b/hibernate-core/src/main/java/org/hibernate/query/derived/AnonymousTupleType.java @@ -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 implements TupleType, DomainType, 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 ); }