2323import  org .hibernate .query .sqm .tree .domain .SqmDomainType ;
2424import  org .hibernate .query .sqm .tree .domain .SqmPluralPersistentAttribute ;
2525import  org .hibernate .query .sqm .tree .select .SqmSelectQuery ;
26+ import  org .hibernate .query .sqm .tree .select .SqmSelection ;
2627import  org .hibernate .query .sqm .tuple .TupleType ;
2728import  org .hibernate .query .SemanticException ;
2829import  org .hibernate .query .sqm .SqmExpressible ;
2930import  org .hibernate .query .sqm .tree .domain .SqmPath ;
3031import  org .hibernate .query .sqm .tree .select .SqmSelectClause ;
3132import  org .hibernate .query .sqm .tree .select .SqmSelectableNode ;
32- import  org .hibernate .query .sqm .tree .select .SqmSubQuery ;
3333import  org .hibernate .spi .NavigablePath ;
3434import  org .hibernate .sql .ast .spi .FromClauseAccess ;
3535import  org .hibernate .sql .ast .spi .SqlSelection ;
@@ -56,11 +56,8 @@ public class AnonymousTupleType<T>
5656	private  final  String [] componentNames ;
5757	private  final  Map <String , Integer > componentIndexMap ;
5858
59- 	public  AnonymousTupleType (SqmSubQuery <T > subQuery ) {
60- 		this ( extractSqmExpressibles ( subQuery  ), extractAliases ( subQuery  ) );
61- 	}
62- 
63- 	public  AnonymousTupleType (SqmSelectableNode <?>[] components , List <String > aliases ) {
59+ 	public  AnonymousTupleType (SqmSelectQuery <T > selectQuery ) {
60+ 		final  SqmSelectableNode <?>[] components  = extractSqmExpressibles ( selectQuery  );
6461		expressibles  = new  SqmBindableType <?>[components .length ];
6562		componentSourcePaths  = new  NavigablePath [components .length ];
6663		for  ( int  i  = 0 ; i  < components .length ; i ++ ) {
@@ -73,9 +70,10 @@ public AnonymousTupleType(SqmSelectableNode<?>[] components, List<String> aliase
7370		//noinspection unchecked 
7471		javaTypeDescriptor  = (JavaType <T >) new  ObjectArrayJavaType ( getTypeDescriptors ( components  ) );
7572		componentIndexMap  = linkedMapOfSize ( components .length  );
73+ 		final  String [] aliases  = extractAliases ( selectQuery  );
7674		for  ( int  i  = 0 ; i  < components .length ; i ++ ) {
7775			final  SqmSelectableNode <?> component  = components [i ];
78- 			String  alias  = aliases  ==  null  ?  null  :  aliases . get (  i  ) ;
76+ 			String  alias  = aliases [ i ] ;
7977			if  ( alias  == null  ) {
8078				alias  = component .getAlias ();
8179			}
@@ -114,29 +112,31 @@ public String getTypeName() {
114112		return  SqmDomainType .super .getTypeName ();
115113	}
116114
117- 	private  static  SqmSelectableNode <?>[] extractSqmExpressibles (SqmSubQuery <?> subQuery ) {
118- 		final  SqmSelectClause  selectClause  = subQuery .getQuerySpec ().getSelectClause ();
115+ 	private  static  SqmSelectableNode <?>[] extractSqmExpressibles (SqmSelectQuery <?> selectQuery ) {
116+ 		final  SqmSelectClause  selectClause  = selectQuery .getQueryPart ()
117+ 				.getFirstQuerySpec ()
118+ 				.getSelectClause ();
119119		if  ( selectClause  == null  || selectClause .getSelectionItems ().isEmpty () ) {
120- 			throw  new  IllegalArgumentException ( "subquery  has no selection items"  );
120+ 			throw  new  IllegalArgumentException ( "selectQuery  has no selection items"  );
121121		}
122- 		// todo: right now, we "snapshot" the state of the subquery  when creating this type, but maybe we shouldn't? 
123- 		//  i.e. what if the subquery  changes later on? Or should we somehow mark the subquery  to signal, 
122+ 		// todo: right now, we "snapshot" the state of the selectQuery  when creating this type, but maybe we shouldn't? 
123+ 		//  i.e. what if the selectQuery  changes later on? Or should we somehow mark the selectQuery  to signal, 
124124		//  that changes to the select clause are invalid after a certain point? 
125125		return  selectClause .getSelectionItems ().toArray ( SqmSelectableNode []::new  );
126126	}
127127
128- 	protected  static  List < String >  extractAliases (SqmSelectQuery <?> subQuery ) {
129- 		final  SqmSelectClause  selectClause  = subQuery .getQueryPart ()
128+ 	private  static  String []  extractAliases (SqmSelectQuery <?> selectQuery ) {
129+ 		final  SqmSelectClause  selectClause  = selectQuery .getQueryPart ()
130130				.getFirstQuerySpec ()
131131				.getSelectClause ();
132- 		final  var  aliases  = new  ArrayList <String >();
133- 		for  (final  var  selection  : selectClause .getSelections ()) {
134- 			final  var  alias  = selection .getAlias ();
132+ 		final  List < String >  aliases  = new  ArrayList <>();
133+ 		for  (final  SqmSelection <?>  selection  : selectClause .getSelections ()) {
134+ 			final  String  alias  = selection .getAlias ();
135135			selection .getSelectableNode ().visitSubSelectableNodes ( node  ->
136136					aliases .add ( alias  == null  ? node .getAlias () : alias  )
137137			);
138138		}
139- 		return  aliases ;
139+ 		return  aliases . toArray ( String []:: new ) ;
140140	}
141141
142142	private  static  JavaType <?>[] getTypeDescriptors (SqmSelectableNode <?>[] components ) {
0 commit comments