From 07551342248cdedb3c6c59825326a6055e53b7a1 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Tue, 6 Aug 2024 15:20:20 +0200 Subject: [PATCH] HHH-18399 Avoid collecting duplicate attribute for to-one inverse table --- .../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 49d951c673..4d69b19171 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 @@ -3547,6 +3547,8 @@ public abstract class AbstractEntityPersister final TableMappingBuilder tableMappingBuilder; final TableMappingBuilder existing = tableBuilderMap.get( tableExpression ); + + final boolean inverseTable = isInverseTable( relativePosition ); if ( existing == null ) { final Consumer selectableConsumerConsumer = tableKeyColumnVisitationSupplier.get(); final List keyColumns = new ArrayList<>(); @@ -3577,7 +3579,7 @@ public abstract class AbstractEntityPersister relativePosition, new EntityTableMapping.KeyMapping( keyColumns, identifierMapping ), !isIdentifierTable && isNullableTable( relativePosition ), - isInverseTable( relativePosition ), + inverseTable, isIdentifierTable, insertExpectations[ relativePosition ], customInsertSql, @@ -3599,7 +3601,9 @@ public abstract class AbstractEntityPersister tableMappingBuilder = existing; } - collectAttributesIndexesForTable( relativePosition, tableMappingBuilder.attributeIndexes::add ); + if ( !inverseTable ) { + collectAttributesIndexesForTable( relativePosition, tableMappingBuilder.attributeIndexes::add ); + } } ); final EntityTableMapping[] list = new EntityTableMapping[tableBuilderMap.size()];