diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 80ae0abca9..1973d0474e 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -29,7 +29,6 @@ import java.util.TreeMap; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Supplier; -import java.util.stream.Collectors; import org.hibernate.AssertionFailure; import org.hibernate.FetchMode; @@ -1809,6 +1808,9 @@ public abstract class AbstractEntityPersister final SelectClause selectClause = rootQuerySpec.getSelectClause(); final List sqlSelections = selectClause.getSqlSelections(); int i = 0; + int columnIndex = 0; + final String[] columnAliases = getSubclassColumnAliasClosure(); + final int columnAliasesSize = columnAliases.length; for ( String identifierAlias : identifierAliases ) { sqlSelections.set( i, @@ -1817,6 +1819,9 @@ public abstract class AbstractEntityPersister new AliasedExpression( sqlSelections.get( i ).getExpression(), identifierAlias + suffix ) ) ); + if ( i < columnAliasesSize && columnAliases[i].equals( identifierAlias ) ) { + columnIndex++; + } i++; } @@ -1842,9 +1847,7 @@ public abstract class AbstractEntityPersister i++; } - final String[] columnAliases = getSubclassColumnAliasClosure(); final String[] formulaAliases = getSubclassFormulaAliasClosure(); - int columnIndex =0; int formulaIndex = 0; for ( ; i < sqlSelections.size(); i++ ) { final SqlSelection sqlSelection = sqlSelections.get( i );