HHH-17108 Error In Native Query when adding two Entity's and using composite key. Error: Unable to find column position by name.

This commit is contained in:
Andrea Boriero 2023-09-08 19:29:03 +02:00 committed by Steve Ebersole
parent 1b92c912df
commit 8ddc6e5105
1 changed files with 6 additions and 3 deletions

View File

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