HHH-15851 Mixup of entities in refresh with BatchSize

This commit is contained in:
Andrea Boriero 2022-12-31 20:21:01 +01:00 committed by Andrea Boriero
parent 72985d7c4d
commit 8b86e082ef
1 changed files with 15 additions and 2 deletions

View File

@ -414,7 +414,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
final Object entityInstanceFromExecutionContext = final Object entityInstanceFromExecutionContext =
rowProcessingState.getJdbcValuesSourceProcessingState().getExecutionContext().getEntityInstance(); rowProcessingState.getJdbcValuesSourceProcessingState().getExecutionContext().getEntityInstance();
if ( isProxyInstance( proxy ) ) { if ( isProxyInstance( proxy ) ) {
if ( this instanceof EntityResultInitializer && entityInstanceFromExecutionContext != null ) { if ( useEntityInstanceFromExecutionContext( entityInstanceFromExecutionContext, persistenceContext.getSession() ) ) {
entityInstance = entityInstanceFromExecutionContext; entityInstance = entityInstanceFromExecutionContext;
registerLoadingEntity( rowProcessingState, entityInstance ); registerLoadingEntity( rowProcessingState, entityInstance );
} }
@ -431,7 +431,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
this.isInitialized = true; this.isInitialized = true;
} }
} }
else if ( this instanceof EntityResultInitializer && entityInstanceFromExecutionContext != null ) { else if ( useEntityInstanceFromExecutionContext( entityInstanceFromExecutionContext, persistenceContext.getSession() ) ) {
entityInstance = entityInstanceFromExecutionContext; entityInstance = entityInstanceFromExecutionContext;
registerLoadingEntity( rowProcessingState, entityInstance ); registerLoadingEntity( rowProcessingState, entityInstance );
} }
@ -445,6 +445,19 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
} }
} }
private boolean useEntityInstanceFromExecutionContext(
Object entityInstanceFromExecutionContext,
SharedSessionContractImplementor session) {
if ( this instanceof EntityResultInitializer
&& entityInstanceFromExecutionContext != null
&& entityKey.getIdentifier()
.equals( entityDescriptor.getIdentifier( entityInstanceFromExecutionContext, session ) )
) {
return true;
}
return false;
}
private void upgradeLockMode(RowProcessingState rowProcessingState) { private void upgradeLockMode(RowProcessingState rowProcessingState) {
if ( lockMode != LockMode.NONE ) { if ( lockMode != LockMode.NONE ) {
final EntityEntry entry = final EntityEntry entry =