@@ -1605,7 +1605,6 @@ private Object initLazyProperties(
16051605
16061606 final var interceptor = asPersistentAttributeInterceptable ( entity ).$$_hibernate_getInterceptor ();
16071607 assert interceptor != null : "Expecting bytecode interceptor to be non-null" ;
1608- final Set <String > initializedLazyAttributeNames = interceptor .getInitializedLazyAttributeNames ();
16091608
16101609 final var lazyAttributesMetadata = getBytecodeEnhancementMetadata ().getLazyAttributesMetadata ();
16111610 final String fetchGroup = lazyAttributesMetadata .getFetchGroupName ( fieldName );
@@ -1615,29 +1614,32 @@ private Object initLazyProperties(
16151614 try {
16161615 Object finalResult = null ;
16171616 final Object [] results = lazySelectLoadPlan .load ( id , session );
1617+ final Set <String > initializedLazyAttributeNames = interceptor .getInitializedLazyAttributeNames ();
16181618 int i = 0 ;
16191619 for ( var fetchGroupAttributeDescriptor : fetchGroupAttributeDescriptors ) {
16201620 final String attributeName = fetchGroupAttributeDescriptor .getName ();
1621- final boolean previousInitialized = initializedLazyAttributeNames .contains ( attributeName );
1622- if ( previousInitialized ) {
1623- // it's already been initialized (e.g. by a write) so we don't want to overwrite
1624- i ++;
1625- // TODO: we should consider un-marking an attribute as dirty based on the selected value
1626- // - we know the current value:
1627- // getPropertyValue( entity, fetchGroupAttributeDescriptor.getAttributeIndex() );
1628- // - we know the selected value (see selectedValue below)
1629- // - we can use the attribute Type to tell us if they are the same
1630- // - assuming entity is a SelfDirtinessTracker we can also know if the attribute is currently
1631- // considered dirty, and if really not dirty we would do the un-marking
1632- // - of course that would mean a new method on SelfDirtinessTracker to allow un-marking
1621+ if ( fieldName .equals ( attributeName ) ) {
1622+ finalResult = results [i ];
16331623 }
1634- else {
1635- final Object result = results [i ++];
1636- if ( initializeLazyProperty ( fieldName , entity , entry , fetchGroupAttributeDescriptor , result ) ) {
1637- finalResult = result ;
1638- interceptor .attributeInitialized ( attributeName );
1639- }
1624+ if ( !initializedLazyAttributeNames .contains ( attributeName ) ) {
1625+ initializeLazyProperty (
1626+ entity ,
1627+ entry ,
1628+ results [i ],
1629+ getPropertyIndex ( attributeName ),
1630+ fetchGroupAttributeDescriptor .getType ()
1631+ );
16401632 }
1633+ // if the attribute has already been initialized (e.g. by a write) we don't want to overwrite
1634+ i ++;
1635+ // TODO: we should consider un-marking an attribute as dirty based on the selected value
1636+ // - we know the current value:
1637+ // getPropertyValue( entity, fetchGroupAttributeDescriptor.getAttributeIndex() );
1638+ // - we know the selected value (see selectedValue below)
1639+ // - we can use the attribute Type to tell us if they are the same
1640+ // - assuming entity is a SelfDirtinessTracker we can also know if the attribute is currently
1641+ // considered dirty, and if really not dirty we would do the un-marking
1642+ // - of course that would mean a new method on SelfDirtinessTracker to allow un-marking
16411643 }
16421644 CORE_LOGGER .doneInitializingLazyProperties ();
16431645 return finalResult ;
@@ -1755,7 +1757,11 @@ private Object copiedLazyPropertyValue(int index, Object propValue) {
17551757 return lazyPropertyTypes [index ].deepCopy ( propValue , factory );
17561758 }
17571759
1758- // Used by Hibernate Reactive
1760+ /**
1761+ * Used by Hibernate Reactive
1762+ * @deprecated
1763+ */
1764+ @ Deprecated (since = "7.2" , forRemoval = true )
17591765 protected boolean initializeLazyProperty (
17601766 final String fieldName ,
17611767 final Object entity ,
0 commit comments