Skip to content

Commit 096e4c2

Browse files
gtoisonmbellade
authored andcommitted
HHH-18885 Introduce DelayedOperation.getAddedEntry() for maps
Extra lazy maps need to persist the added entry (key and value), not the added value. Let PersistentMap.AbstractMapValueDelayedOperation return the added entry so OneToManyPersister.writeIndex() can execute the queued operation.
1 parent c46738f commit 096e4c2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ public final Iterator<E> queuedAdditionIterator() {
874874

875875
@Override
876876
public E next() {
877-
return operationQueue.get( index++ ).getAddedInstance();
877+
return operationQueue.get( index++ ).getAddedEntry();
878878
}
879879

880880
@Override
@@ -1248,6 +1248,10 @@ protected interface DelayedOperation<E> {
12481248
void operate();
12491249

12501250
E getAddedInstance();
1251+
1252+
default E getAddedEntry() {
1253+
return getAddedInstance();
1254+
}
12511255

12521256
E getOrphan();
12531257
}

hibernate-core/src/main/java/org/hibernate/collection/spi/PersistentMap.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,12 @@ protected AbstractMapValueDelayedOperation(K index, E addedValue, E orphan) {
539539
protected final K getIndex() {
540540
return index;
541541
}
542+
543+
@Override
544+
public E getAddedEntry() {
545+
// The (E) cast is very hacky because E is not Map.Entry but we need it to conform to PersistentCollection.queuedAdditionIterator()
546+
return (E) Map.entry( getIndex(), getAddedInstance() );
547+
}
542548
}
543549

544550
final class Put extends AbstractMapValueDelayedOperation {

0 commit comments

Comments
 (0)