diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java index a25d4af054..3e2a618ad4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java @@ -41,10 +41,9 @@ import org.hibernate.sql.results.graph.DomainResultCreationState; import org.hibernate.sql.results.graph.Fetch; import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.Fetchable; -import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableFetchImpl; -import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableResultImpl; import org.hibernate.sql.results.graph.embeddable.internal.NonAggregatedIdentifierMappingFetch; import org.hibernate.sql.results.graph.embeddable.internal.NonAggregatedIdentifierMappingResult; +import org.hibernate.sql.results.graph.entity.LoadingEntityEntry; /** * A "non-aggregated" composite identifier. @@ -274,8 +273,7 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif Object o = mappedIdAttributeMapping.getPropertyAccess().getGetter().get( id ); if ( attribute instanceof ToOneAttributeMapping && !( mappedIdAttributeMapping instanceof ToOneAttributeMapping ) ) { final ToOneAttributeMapping toOneAttributeMapping = (ToOneAttributeMapping) attribute; - final EntityPersister entityPersister = toOneAttributeMapping.getEntityMappingType() - .getEntityPersister(); + final EntityPersister entityPersister = toOneAttributeMapping.getEntityMappingType().getEntityPersister(); final EntityKey entityKey = session.generateEntityKey( o, entityPersister ); final PersistenceContext persistenceContext = session.getPersistenceContext(); // it is conceivable there is a proxy, so check that first @@ -290,6 +288,21 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif toOneAttributeMapping.getAttributeName() ); } + if ( o == null ) { + final LoadingEntityEntry loadingEntityEntry = persistenceContext.getLoadContexts() + .findLoadingEntityEntry( entityKey ); + if ( loadingEntityEntry != null ) { + o = loadingEntityEntry.getEntityInstance(); + } + else { + o = session.internalLoad( + entityPersister.getEntityName(), + entityKey.getIdentifier(), + true, + true + ); + } + } } } propertyValues[i] = o;