HHH-16334 Persist and load an entity with an all-delete-orphan collection null
This commit is contained in:
parent
6c9d9666a4
commit
b6fa9c1295
|
@ -21,6 +21,7 @@ import org.hibernate.sql.results.graph.FetchParentAccess;
|
|||
import org.hibernate.sql.results.graph.collection.CollectionInitializer;
|
||||
import org.hibernate.sql.results.graph.collection.CollectionLoadingLogger;
|
||||
import org.hibernate.sql.results.graph.collection.LoadingCollectionEntry;
|
||||
import org.hibernate.sql.results.graph.entity.EntityInitializer;
|
||||
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;
|
||||
|
||||
/**
|
||||
|
@ -91,6 +92,12 @@ public abstract class AbstractCollectionInitializer implements CollectionInitial
|
|||
|
||||
protected void resolveInstance(RowProcessingState rowProcessingState, boolean isEager) {
|
||||
if ( collectionKey != null ) {
|
||||
if ( parentAccess != null ) {
|
||||
final EntityInitializer parentEntityInitializer = parentAccess.findFirstEntityInitializer();
|
||||
if ( parentEntityInitializer != null && parentEntityInitializer.isEntityInitialized() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
final SharedSessionContractImplementor session = rowProcessingState.getSession();
|
||||
final PersistenceContext persistenceContext = session.getPersistenceContext();
|
||||
final FetchParentAccess fetchParentAccess = parentAccess.findFirstEntityDescriptorAccess();
|
||||
|
|
|
@ -11,7 +11,6 @@ import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
|||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.results.graph.DomainResultAssembler;
|
||||
import org.hibernate.sql.results.graph.FetchParentAccess;
|
||||
import org.hibernate.sql.results.graph.entity.EntityInitializer;
|
||||
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;
|
||||
|
||||
/**
|
||||
|
@ -30,12 +29,6 @@ public class DelayedCollectionInitializer extends AbstractCollectionInitializer
|
|||
|
||||
@Override
|
||||
public void resolveInstance(RowProcessingState rowProcessingState) {
|
||||
if ( parentAccess != null ) {
|
||||
final EntityInitializer parentEntityInitializer = parentAccess.findFirstEntityInitializer();
|
||||
if ( parentEntityInitializer != null && parentEntityInitializer.isEntityInitialized() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
resolveInstance( rowProcessingState, false );
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ package org.hibernate.sql.results.graph.entity;
|
|||
import java.util.Collection;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.StaleObjectStateException;
|
||||
|
@ -41,7 +42,6 @@ import org.hibernate.metamodel.mapping.ManagedMappingType;
|
|||
import org.hibernate.metamodel.mapping.ModelPart;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
import org.hibernate.proxy.map.MapProxy;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
|
@ -563,18 +563,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
|||
}
|
||||
|
||||
private boolean isExistingEntityInitialized(Object existingEntity) {
|
||||
final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( entityInstance );
|
||||
if ( lazyInitializer != null ) {
|
||||
return !lazyInitializer.isUninitialized();
|
||||
}
|
||||
else if ( isPersistentAttributeInterceptable( existingEntity ) ) {
|
||||
final PersistentAttributeInterceptor persistentAttributeInterceptor =
|
||||
asPersistentAttributeInterceptable( entityInstance ).$$_hibernate_getInterceptor();
|
||||
return persistentAttributeInterceptor != null
|
||||
&& !( persistentAttributeInterceptor instanceof EnhancementAsProxyLazinessInterceptor );
|
||||
}
|
||||
|
||||
return true;
|
||||
return Hibernate.isInitialized( existingEntity );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.util.Map;
|
|||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||
import org.hibernate.sql.results.graph.Initializer;
|
||||
import org.hibernate.sql.results.graph.collection.internal.AbstractCollectionInitializer;
|
||||
import org.hibernate.sql.results.graph.entity.internal.EntityDelayedFetchInitializer;
|
||||
import org.hibernate.sql.results.graph.entity.internal.EntitySelectFetchInitializer;
|
||||
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;
|
||||
|
@ -115,7 +116,9 @@ public final class InitializersList {
|
|||
}
|
||||
|
||||
private static boolean initializeFirst(final Initializer initializer) {
|
||||
return !( initializer instanceof EntityDelayedFetchInitializer ) && !( initializer instanceof EntitySelectFetchInitializer );
|
||||
return !( initializer instanceof EntityDelayedFetchInitializer )
|
||||
&& !( initializer instanceof EntitySelectFetchInitializer )
|
||||
&& !( initializer instanceof AbstractCollectionInitializer );
|
||||
}
|
||||
|
||||
InitializersList build(final Map<NavigablePath, Initializer> initializerMap) {
|
||||
|
|
Loading…
Reference in New Issue