@@ -180,8 +180,7 @@ public SqmQuerySource getQuerySource() {
180180 @ Override
181181 public SqmQuerySpec <T > getQuerySpec () {
182182 if ( querySource == CRITERIA ) {
183- final SqmQueryPart <T > queryPart = getQueryPart ();
184- if ( queryPart instanceof SqmQuerySpec <T > querySpec ) {
183+ if ( getQueryPart () instanceof SqmQuerySpec <T > querySpec ) {
185184 return querySpec ;
186185 }
187186 throw new IllegalStateException (
@@ -355,9 +354,8 @@ public SqmSelectStatement<T> multiselect(Selection<?>... selections) {
355354 checkSelectionIsJpaCompliant ( selection );
356355 }
357356 }
358-
359- final Selection <? extends T > resultSelection = getResultSelection ( selections );
360- getQuerySpec ().getSelectClause ().setSelection ( (SqmSelectableNode <?>) resultSelection );
357+ getQuerySpec ().getSelectClause ()
358+ .setSelection ( (SqmSelectableNode <?>) getResultSelection ( selections ) );
361359 return this ;
362360 }
363361
@@ -368,32 +366,29 @@ public SqmSelectStatement<T> multiselect(List<Selection<?>> selectionList) {
368366 checkSelectionIsJpaCompliant ( selection );
369367 }
370368 }
371- final Selection <? extends T > resultSelection = getResultSelection ( selectionList );
372- getQuerySpec (). getSelectClause (). setSelection ( (SqmSelectableNode <?>) resultSelection );
369+ getQuerySpec (). getSelectClause ()
370+ . setSelection ( (SqmSelectableNode <?>) getResultSelection ( selectionList ) );
373371 return this ;
374372 }
375373
376- @ SuppressWarnings ("unchecked" )
377- private Selection <? extends T > getResultSelection (List <?> selections ) {
374+ private JpaSelection <?> getResultSelection (List <Selection <?>> selections ) {
378375 final Class <T > resultType = getResultType ();
379376 if ( resultType == null || resultType == Object .class ) {
380- switch ( selections .size () ) {
381- case 0 :
382- throw new IllegalArgumentException ( "Empty selections passed to criteria query typed as Object" );
383- case 1 :
384- return (Selection <? extends T >) selections .get ( 0 );
385- default :
386- return (Selection <? extends T >) nodeBuilder ().array ( (List <Selection <?>>) selections );
387- }
377+ return switch ( selections .size () ) {
378+ case 0 -> throw new IllegalArgumentException (
379+ "empty selections passed to criteria query typed as Object" );
380+ case 1 -> (JpaSelection <?>) selections .get ( 0 );
381+ default -> nodeBuilder ().array ( selections );
382+ };
388383 }
389384 else if ( Tuple .class .isAssignableFrom ( resultType ) ) {
390- return ( Selection <? extends T >) nodeBuilder ().tuple ( ( List < Selection <?>>) selections );
385+ return nodeBuilder ().tuple ( selections );
391386 }
392387 else if ( resultType .isArray () ) {
393- return nodeBuilder ().array ( resultType , ( List <? extends JpaSelection <?>>) selections );
388+ return nodeBuilder ().array ( resultType , selections );
394389 }
395390 else {
396- return nodeBuilder ().construct ( resultType , ( List <? extends JpaSelection <?>>) selections );
391+ return nodeBuilder ().construct ( resultType , selections );
397392 }
398393 }
399394
@@ -566,10 +561,12 @@ private <S> void aliasSelections(SqmQueryPart<S> queryPart) {
566561 final SqmQuerySpec <S > querySpec = queryPart .getFirstQuerySpec ();
567562 final LinkedHashSet <JpaSelection <?>> newSelections = new LinkedHashSet <>();
568563 aliasSelection ( querySpec .getSelection (), newSelections );
564+ final JpaSelection <?> selection =
565+ newSelections .size () == 1
566+ ? newSelections .iterator ().next ()
567+ : nodeBuilder ().tuple ( newSelections .toArray ( new JpaSelection <?>[0 ] ) );
569568 //noinspection unchecked
570- querySpec .setSelection ( (JpaSelection <S >) ( newSelections .size () == 1 ?
571- newSelections .iterator ().next () :
572- nodeBuilder ().tuple ( newSelections .toArray ( new JpaSelection <?>[0 ] ) ) ) );
569+ querySpec .setSelection ( (JpaSelection <S >) selection );
573570 }
574571 else {
575572 ( (SqmQueryGroup <?>) queryPart ).getQueryParts ().forEach ( this ::aliasSelections );
0 commit comments