Skip to content

Commit 3bcd57f

Browse files
committed
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.Put return the added entry so OneToManyPersister.writeIndex() can execute the queued operation.
1 parent 14c6cf5 commit 3bcd57f

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
@@ -849,7 +849,7 @@ public final Iterator<E> queuedAdditionIterator() {
849849

850850
@Override
851851
public E next() {
852-
return operationQueue.get( index++ ).getAddedInstance();
852+
return operationQueue.get( index++ ).getAddedEntry();
853853
}
854854

855855
@Override
@@ -1204,6 +1204,10 @@ protected interface DelayedOperation<E> {
12041204
void operate();
12051205

12061206
E getAddedInstance();
1207+
1208+
default E getAddedEntry() {
1209+
return getAddedInstance();
1210+
}
12071211

12081212
E getOrphan();
12091213
}

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
@@ -540,6 +540,12 @@ public Put(K index, E addedValue, E orphan) {
540540
public void operate() {
541541
map.put( getIndex(), getAddedInstance() );
542542
}
543+
544+
@Override
545+
public E getAddedEntry() {
546+
// The (E) cast is very hacky because E is not Map.Entry but we need it to conform to PersistentCollection.queuedAdditionIterator()
547+
return (E) Map.entry( getIndex(), getAddedInstance() );
548+
}
543549
}
544550

545551
final class Remove extends AbstractMapValueDelayedOperation {

0 commit comments

Comments
 (0)