HHH-16272 Hibernate 6 fails to refresh when collections are accessed in entity setter method when access type is property
This commit is contained in:
parent
8c9497b63a
commit
53b3ea6b3b
|
@ -52,7 +52,6 @@ import org.hibernate.sql.results.graph.DomainResultAssembler;
|
||||||
import org.hibernate.sql.results.graph.Fetch;
|
import org.hibernate.sql.results.graph.Fetch;
|
||||||
import org.hibernate.sql.results.graph.Initializer;
|
import org.hibernate.sql.results.graph.Initializer;
|
||||||
import org.hibernate.sql.results.graph.basic.BasicResultAssembler;
|
import org.hibernate.sql.results.graph.basic.BasicResultAssembler;
|
||||||
import org.hibernate.sql.results.graph.entity.internal.EntityResultInitializer;
|
|
||||||
import org.hibernate.sql.results.internal.NullValueAssembler;
|
import org.hibernate.sql.results.internal.NullValueAssembler;
|
||||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingOptions;
|
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingOptions;
|
||||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingState;
|
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingState;
|
||||||
|
@ -498,10 +497,9 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
||||||
|
|
||||||
final PersistenceContext persistenceContext = rowProcessingState.getSession().getPersistenceContextInternal();
|
final PersistenceContext persistenceContext = rowProcessingState.getSession().getPersistenceContextInternal();
|
||||||
final Object proxy = getProxy( persistenceContext );
|
final Object proxy = getProxy( persistenceContext );
|
||||||
final Object entityInstanceFromExecutionContext =
|
final Object entityInstanceFromExecutionContext = getEntityInstanceFromExecutionContext( rowProcessingState );
|
||||||
rowProcessingState.getJdbcValuesSourceProcessingState().getExecutionContext().getEntityInstance();
|
|
||||||
if ( isProxyInstance( proxy ) ) {
|
if ( isProxyInstance( proxy ) ) {
|
||||||
if ( useEntityInstanceFromExecutionContext( entityInstanceFromExecutionContext, persistenceContext.getSession() ) ) {
|
if ( entityInstanceFromExecutionContext != null ) {
|
||||||
entityInstance = entityInstanceFromExecutionContext;
|
entityInstance = entityInstanceFromExecutionContext;
|
||||||
registerLoadingEntity( rowProcessingState, entityInstance );
|
registerLoadingEntity( rowProcessingState, entityInstance );
|
||||||
}
|
}
|
||||||
|
@ -518,7 +516,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
||||||
this.isInitialized = true;
|
this.isInitialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( useEntityInstanceFromExecutionContext( entityInstanceFromExecutionContext, persistenceContext.getSession() ) ) {
|
else if ( entityInstanceFromExecutionContext != null ) {
|
||||||
entityInstance = entityInstanceFromExecutionContext;
|
entityInstance = entityInstanceFromExecutionContext;
|
||||||
registerLoadingEntity( rowProcessingState, entityInstance );
|
registerLoadingEntity( rowProcessingState, entityInstance );
|
||||||
}
|
}
|
||||||
|
@ -532,13 +530,8 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean useEntityInstanceFromExecutionContext(
|
protected Object getEntityInstanceFromExecutionContext(RowProcessingState rowProcessingState) {
|
||||||
Object entityInstanceFromExecutionContext,
|
return null;
|
||||||
SharedSessionContractImplementor session) {
|
|
||||||
return this instanceof EntityResultInitializer
|
|
||||||
&& entityInstanceFromExecutionContext != null
|
|
||||||
&& entityKey.getIdentifier()
|
|
||||||
.equals( entityDescriptor.getIdentifier( entityInstanceFromExecutionContext, session ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void upgradeLockMode(RowProcessingState rowProcessingState) {
|
private void upgradeLockMode(RowProcessingState rowProcessingState) {
|
||||||
|
@ -803,8 +796,6 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
entityDescriptor.setIdentifier( toInitialize, entityIdentifier, session );
|
|
||||||
|
|
||||||
resolvedEntityState = extractConcreteTypeStateValues( rowProcessingState );
|
resolvedEntityState = extractConcreteTypeStateValues( rowProcessingState );
|
||||||
|
|
||||||
if ( isPersistentAttributeInterceptable(toInitialize) ) {
|
if ( isPersistentAttributeInterceptable(toInitialize) ) {
|
||||||
|
@ -859,6 +850,8 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert concreteDescriptor.getIdentifier( entityInstance, session ) != null;
|
||||||
|
|
||||||
final StatisticsImplementor statistics = session.getFactory().getStatistics();
|
final StatisticsImplementor statistics = session.getFactory().getStatistics();
|
||||||
if ( statistics.isStatisticsEnabled() ) {
|
if ( statistics.isStatisticsEnabled() ) {
|
||||||
if ( !rowProcessingState.isQueryCacheHit() ) {
|
if ( !rowProcessingState.isQueryCacheHit() ) {
|
||||||
|
|
|
@ -8,12 +8,14 @@ package org.hibernate.sql.results.graph.entity.internal;
|
||||||
|
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
import org.hibernate.spi.NavigablePath;
|
import org.hibernate.spi.NavigablePath;
|
||||||
|
import org.hibernate.sql.exec.spi.ExecutionContext;
|
||||||
import org.hibernate.sql.results.graph.AssemblerCreationState;
|
import org.hibernate.sql.results.graph.AssemblerCreationState;
|
||||||
import org.hibernate.sql.results.graph.DomainResult;
|
import org.hibernate.sql.results.graph.DomainResult;
|
||||||
import org.hibernate.sql.results.graph.Fetch;
|
import org.hibernate.sql.results.graph.Fetch;
|
||||||
import org.hibernate.sql.results.graph.basic.BasicFetch;
|
import org.hibernate.sql.results.graph.basic.BasicFetch;
|
||||||
import org.hibernate.sql.results.graph.entity.AbstractEntityInitializer;
|
import org.hibernate.sql.results.graph.entity.AbstractEntityInitializer;
|
||||||
import org.hibernate.sql.results.graph.entity.EntityResultGraphNode;
|
import org.hibernate.sql.results.graph.entity.EntityResultGraphNode;
|
||||||
|
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializer for cases where the entity is a root domain selection
|
* Initializer for cases where the entity is a root domain selection
|
||||||
|
@ -57,4 +59,16 @@ public class EntityResultInitializer extends AbstractEntityInitializer {
|
||||||
return CONCRETE_NAME + "(" + getNavigablePath() + ")";
|
return CONCRETE_NAME + "(" + getNavigablePath() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object getEntityInstanceFromExecutionContext(RowProcessingState rowProcessingState) {
|
||||||
|
final ExecutionContext executionContext = rowProcessingState.getJdbcValuesSourceProcessingState()
|
||||||
|
.getExecutionContext();
|
||||||
|
final Object entityInstanceFromExecutionContext = executionContext.getEntityInstance();
|
||||||
|
if ( entityInstanceFromExecutionContext != null
|
||||||
|
&& getEntityKey().getIdentifier().equals( executionContext.getEntityId() ) ) {
|
||||||
|
return entityInstanceFromExecutionContext;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue