HHH-16811 Dirty property lost and not detected with Batch Fetch, Embedded and FetchMode SELECT

This commit is contained in:
Andrea Boriero 2023-06-27 13:59:18 +02:00 committed by Andrea Boriero
parent e66da212af
commit 90bb46a465
2 changed files with 22 additions and 11 deletions

View File

@ -186,8 +186,8 @@ public abstract class AbstractEmbeddableInitializer extends AbstractFetchParentA
case NULL: case NULL:
return; return;
case INITIAL: case INITIAL:
if ( isParentInstanceNull() ) { state = determinInitialState();
state = State.NULL; if ( state != State.INITIAL ) {
return; return;
} }
@ -269,9 +269,24 @@ public abstract class AbstractEmbeddableInitializer extends AbstractFetchParentA
); );
} }
private boolean isParentInstanceNull() { private State determinInitialState(){
final EntityInitializer entityInitializer = getOwningEntityInitializer();
if ( entityInitializer != null ) {
if ( entityInitializer.getParentKey() == null ) {
// parent instance is null;
return State.NULL;
}
else if ( entityInitializer.isEntityInitialized() ) {
// parent instance has been initialized, we do not need to inject the state
return State.INJECTED;
}
}
return State.INITIAL;
}
private EntityInitializer getOwningEntityInitializer() {
if ( isPartOfKey ) { if ( isPartOfKey ) {
return false; return null;
} }
FetchParentAccess parentAccess = fetchParentAccess; FetchParentAccess parentAccess = fetchParentAccess;
@ -280,16 +295,11 @@ public abstract class AbstractEmbeddableInitializer extends AbstractFetchParentA
: "isPartOfKey should have been true in this case"; : "isPartOfKey should have been true in this case";
parentAccess = parentAccess.getFetchParentAccess(); parentAccess = parentAccess.getFetchParentAccess();
} }
if ( parentAccess == null ) { if ( parentAccess == null ) {
return false; return null;
} }
final EntityInitializer entityInitializer = parentAccess.asEntityInitializer(); final EntityInitializer entityInitializer = parentAccess.asEntityInitializer();
if ( entityInitializer != null && entityInitializer.getParentKey() == null ) { return entityInitializer;
return true;
}
return false;
} }
private void extractRowState(RowProcessingState processingState) { private void extractRowState(RowProcessingState processingState) {

View File

@ -75,6 +75,7 @@ public abstract class AbstractBatchEntitySelectFetchInitializer extends Abstract
RowProcessingState rowProcessingState, RowProcessingState rowProcessingState,
ToOneAttributeMapping referencedModelPart, ToOneAttributeMapping referencedModelPart,
FetchParentAccess parentAccess) { FetchParentAccess parentAccess) {
if ( state != State.UNINITIALIZED ) { if ( state != State.UNINITIALIZED ) {
return; return;
} }