Skip to content

Commit e57406a

Browse files
marko-bekhtambellade
authored andcommitted
HHH-19856 Account for nested initialization when loading lazy property
1 parent e04b8f3 commit e57406a

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,26 +1618,28 @@ private Object initLazyProperties(
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

Comments
 (0)