Skip to content

Commit 565c1da

Browse files
committed
HHH-19805 Update unfetched attributes of already initialized entity when data is fetched
1 parent c30db7c commit 565c1da

File tree

5 files changed

+214
-56
lines changed

5 files changed

+214
-56
lines changed

hibernate-core/src/main/java/org/hibernate/internal/util/ImmutableBitSet.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
package org.hibernate.internal.util;
66

7+
import org.checkerframework.checker.nullness.qual.Nullable;
8+
79
import java.util.Arrays;
810
import java.util.BitSet;
911

@@ -26,6 +28,10 @@ private ImmutableBitSet(long[] words) {
2628
this.words = words;
2729
}
2830

31+
public static ImmutableBitSet valueOfOrEmpty(@Nullable BitSet bitSet) {
32+
return bitSet == null ? EMPTY : valueOf( bitSet );
33+
}
34+
2935
public static ImmutableBitSet valueOf(BitSet bitSet) {
3036
final long[] words = bitSet.toLongArray();
3137
return words.length == 0 ? EMPTY : new ImmutableBitSet( words );
@@ -70,4 +76,7 @@ public boolean equals(Object obj) {
7076
return Arrays.equals( words, set.words );
7177
}
7278

79+
public BitSet toBitSet() {
80+
return BitSet.valueOf( words );
81+
}
7382
}

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ private Fetch createDelayedCollectionFetch(
596596
// returning a domain result assembler that returns LazyPropertyInitializer.UNFETCHED_PROPERTY
597597
final var containingEntityMapping = findContainingEntityMapping();
598598
final boolean unfetched;
599-
if ( fetchParent.getReferencedModePart() == containingEntityMapping
599+
if ( fetchParent.getReferencedMappingContainer() == containingEntityMapping
600600
&& containingEntityMapping.getEntityPersister().getPropertyLaziness()[getStateArrayPosition()] ) {
601601
collectionKeyDomainResult = null;
602602
unfetched = true;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.hibernate.id.IdentifierGenerator;
7272
import org.hibernate.id.OptimizableGenerator;
7373
import org.hibernate.internal.FilterHelper;
74+
import org.hibernate.internal.util.ImmutableBitSet;
7475
import org.hibernate.internal.util.IndexedConsumer;
7576
import org.hibernate.internal.util.MarkerObject;
7677
import org.hibernate.internal.util.StringHelper;
@@ -1733,6 +1734,11 @@ protected boolean initializeLazyProperty(
17331734
final Object propValue) {
17341735
final int propertyNumber = lazyPropertyNumbers[index];
17351736
setPropertyValue( entity, propertyNumber, propValue );
1737+
if ( entry.getMaybeLazySet() != null ) {
1738+
var bitSet = entry.getMaybeLazySet().toBitSet();
1739+
bitSet.set( propertyNumber );
1740+
entry.setMaybeLazySet( ImmutableBitSet.valueOf( bitSet ) );
1741+
}
17361742
final var loadedState = entry.getLoadedState();
17371743
if ( loadedState != null ) {
17381744
// object have been loaded with setReadOnly(true); HHH-2236
@@ -1767,6 +1773,11 @@ protected boolean initializeLazyProperty(
17671773
// Used by Hibernate Reactive
17681774
protected void initializeLazyProperty(Object entity, EntityEntry entry, Object propValue, int index, Type type) {
17691775
setPropertyValue( entity, index, propValue );
1776+
if ( entry.getMaybeLazySet() != null ) {
1777+
var bitSet = entry.getMaybeLazySet().toBitSet();
1778+
bitSet.set( index );
1779+
entry.setMaybeLazySet( ImmutableBitSet.valueOf( bitSet ) );
1780+
}
17701781
final var loadedState = entry.getLoadedState();
17711782
if ( loadedState != null ) {
17721783
// object has been loaded with setReadOnly(true); HHH-2236

0 commit comments

Comments
 (0)