From fbfb10421df9b87b52066dc6421a3ea417edf1a0 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 18 Sep 2024 17:35:01 +0200 Subject: [PATCH] HHH-18631 AssertionError when loading an entity after removing another, associated entity --- .../graph/entity/internal/EntityInitializerImpl.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 d9610b4f03b4..75e5b4f28a2c 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 @@ -48,6 +48,7 @@ import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.EntityValuedModelPart; import org.hibernate.metamodel.mapping.EntityVersionMapping; +import org.hibernate.metamodel.mapping.ForeignKeyDescriptor; import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping; import org.hibernate.persister.entity.EntityPersister; @@ -85,7 +86,6 @@ import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable; import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable; import static org.hibernate.internal.util.NullnessUtil.castNonNull; -import static org.hibernate.metamodel.mapping.ForeignKeyDescriptor.Nature.TARGET; import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer; /** @@ -933,9 +933,8 @@ public void resolveInstance(Object instance, EntityInitializerData data) { if ( data.entityHolder == null ) { // Entity was most probably removed in the same session without setting the reference to null resolveKey( data ); - assert data.getState() == State.MISSING; - assert referencedModelPart instanceof ToOneAttributeMapping - && ( (ToOneAttributeMapping) referencedModelPart ).getSideNature() == TARGET; + assert referencedModelPart instanceof ToOneAttributeMapping toOneAttributeMapping + && toOneAttributeMapping.getSideNature() == ForeignKeyDescriptor.Nature.KEY; return; } if ( data.concreteDescriptor.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading()