Skip to content

Commit

Permalink
HHH-15634 Lazy basic property does not get updated on change
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 authored and beikov committed Oct 31, 2022
1 parent e333af6 commit 33053cd
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3806,7 +3806,7 @@ public void update(
if ( entry == null && !isMutable() ) {
throw new IllegalStateException( "Updating immutable entity that is not in session yet!" );
}
if ( ( entityMetamodel.isDynamicUpdate() && dirtyFields != null ) ) {
if ( dirtyFields != null && entityMetamodel.isDynamicUpdate() ) {
// We need to generate the UPDATE SQL when dynamic-update="true"
propsToUpdate = getPropertiesToUpdate( dirtyFields, hasDirtyCollection );
// don't need to check laziness (dirty checking algorithm handles that)
Expand All @@ -3817,6 +3817,24 @@ public void update(
null;
}
}
else if ( dirtyFields != null && hasUninitializedLazyProperties( object ) && hasLazyDirtyFields( dirtyFields ) ) {
// We need to generate the UPDATE SQL when there are dirty lazy fields
propsToUpdate = getPropertiesToUpdate( dirtyFields, hasDirtyCollection );
// don't need to check laziness (dirty checking algorithm handles that)
final boolean[] propertyLaziness = getPropertyLaziness();
// we add also all the non lazy properties because dynamic update is false
for ( int i = 0; i < propertyLaziness.length; i++ ) {
if ( propertyLaziness[i] == false ) {
propsToUpdate[i] = true;
}
}
updateStrings = new String[span];
for ( int j = 0; j < span; j++ ) {
updateStrings[j] = tableUpdateNeeded[j] ?
generateUpdateString( propsToUpdate, j, oldFields, j == 0 && rowId != null ) :
null;
}
}
else if ( !isModifiableEntity( entry ) ) {
// We need to generate UPDATE SQL when a non-modifiable entity (e.g., read-only or immutable)
// needs:
Expand Down Expand Up @@ -3865,6 +3883,17 @@ else if ( !isModifiableEntity( entry ) ) {
}
}

private boolean hasLazyDirtyFields(int[] dirtyFields) {
final boolean[] propertyLaziness = getPropertyLaziness();
for ( int i = 0; i < dirtyFields.length; i++ ) {
if ( propertyLaziness[dirtyFields[i]] ) {
return true;
}
}
return false;
}

@Override
public Serializable insert(Object[] fields, Object object, SharedSessionContractImplementor session)
throws HibernateException {
// apply any pre-insert in-memory value generation
Expand Down

0 comments on commit 33053cd

Please sign in to comment.