From d4ef44db00e258d843f05904609a984fa78a9ed4 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 16 Sep 2024 17:52:13 +0200 Subject: [PATCH] HHH-18608 NPE in EntityInitializerImpl.resolveInstanceSubInitializers --- .../entity/AbstractEntityPersister.java | 10 +++++++++ .../internal/EntityInitializerImpl.java | 21 +++++++++++++++++-- 2 files changed, 29 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 c54a747c14..97c05015cd 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 @@ -276,6 +276,7 @@ import org.hibernate.type.CollectionType; import org.hibernate.type.ComponentType; import org.hibernate.type.CompositeType; import org.hibernate.type.EntityType; +import org.hibernate.type.ManyToOneType; import org.hibernate.type.Type; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.MutabilityPlan; @@ -1183,6 +1184,15 @@ public abstract class AbstractEntityPersister uniqueKeys.add( new UniqueKeyEntry( ukName, index, type ) ); } } + else if ( associationType instanceof ManyToOneType manyToOneType + && manyToOneType.isLogicalOneToOne() && manyToOneType.isReferenceToPrimaryKey() ) { + final AttributeMapping attributeMapping = aep.findAttributeMapping( manyToOneType.getPropertyName() ); + if ( attributeMapping != null ) { + final int index = attributeMapping.getStateArrayPosition(); + final Type type = aep.getPropertyTypes()[index]; + uniqueKeys.add( new UniqueKeyEntry( manyToOneType.getPropertyName(), index, type ) ); + } + } } } return toSmallList( uniqueKeys ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityInitializerImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityInitializerImpl.java index 2b8a643245..77099a5e31 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityInitializerImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityInitializerImpl.java @@ -23,6 +23,7 @@ import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLaziness import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.EntityDataAccess; import org.hibernate.cache.spi.entry.CacheEntry; +import org.hibernate.engine.internal.ForeignKeys; import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.EntityHolder; import org.hibernate.engine.spi.EntityKey; @@ -75,6 +76,7 @@ import org.hibernate.sql.results.internal.NullValueAssembler; import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingOptions; import org.hibernate.sql.results.jdbc.spi.RowProcessingState; import org.hibernate.stat.spi.StatisticsImplementor; +import org.hibernate.type.ManyToOneType; import org.hibernate.type.Type; import org.hibernate.type.descriptor.java.MutabilityPlan; @@ -622,6 +624,8 @@ public class EntityInitializerImpl extends AbstractInitializer[] initializers; final ImmutableBitSet maybeLazySet; if ( data.entityHolder.getEntityInitializer() == this ) { @@ -981,11 +985,13 @@ public class EntityInitializerImpl extends AbstractInitializer initializer = identifierAssembler.getInitializer(); @@ -1582,11 +1588,22 @@ public class EntityInitializerImpl extends AbstractInitializer