diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 5d27a82f8c..b8129fce9e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -8258,7 +8258,15 @@ public abstract class BaseSqmToSqlAstConverter extends Base offset = countIndividualSelections( ( (SqmDynamicInstantiation) selectableNode ).getArguments() ) - 1; } else if ( selectableNode instanceof SqmJpaCompoundSelection ) { - offset += ( (SqmJpaCompoundSelection) selectableNode ).getSelectionItems().size() - 1; + for ( SqmSelectableNode node : ( (SqmJpaCompoundSelection) selectableNode ).getSelectionItems() ) { + if ( node instanceof SqmDynamicInstantiation ) { + offset += countIndividualSelections( ( (SqmDynamicInstantiation) node ).getArguments() ) ; + } + else { + offset += 1; + } + } + offset -= 1; } } return offset + selections.size();