From d6e695055ec06d831e6dab56b9ce698b41e49b81 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 8 Sep 2023 19:29:03 +0200 Subject: [PATCH] HHH-17108 Error In Native Query when adding two Entity's and using composite key. Error: Unable to find column position by name. --- .../persister/entity/AbstractEntityPersister.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 c9d86077ca..b26a71c195 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 @@ -1754,6 +1754,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, @@ -1762,6 +1765,9 @@ public abstract class AbstractEntityPersister new AliasedExpression( sqlSelections.get( i ).getExpression(), identifierAlias + suffix ) ) ); + if ( i < columnAliasesSize && columnAliases[i].equals( identifierAlias ) ) { + columnIndex++; + } i++; } @@ -1787,9 +1793,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 );