Skip to content

Commit f35a6e3

Browse files
committed
[#709] Fix call to non reactive delete method
When setting an association with orphan removal to null we should call the reavtive delete.
1 parent 002e56a commit f35a6e3

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/engine/impl/Cascade.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import java.util.Collection;
3636
import java.util.Collections;
37-
import java.util.HashSet;
3837
import java.util.Iterator;
3938
import java.util.concurrent.CompletionStage;
4039

@@ -350,19 +349,20 @@ private void cascadeLogicalOneToOneOrphanRemoval(
350349
);
351350
}
352351

352+
final Object loaded = loadedValue;
353353
if ( type.isAssociationType()
354354
&& ( (AssociationType) type ).getForeignKeyDirection()
355355
.equals(ForeignKeyDirection.TO_PARENT) ) {
356356
// If FK direction is to-parent, we must remove the orphan *before* the queued update(s)
357357
// occur. Otherwise, replacing the association on a managed entity, without manually
358358
// nulling and flushing, causes FK constraint violations.
359-
ReactiveSession session = (ReactiveSession) eventSource;
360-
final Object finalLoadedValue = loadedValue;
361-
stage = stage.thenCompose( v -> session.reactiveRemoveOrphanBeforeUpdates( entityName, finalLoadedValue ) );
359+
stage = stage.thenCompose( v -> ( (ReactiveSession) eventSource )
360+
.reactiveRemoveOrphanBeforeUpdates( entityName, loaded ) );
362361
}
363362
else {
364363
// Else, we must delete after the updates.
365-
eventSource.delete( entityName, loadedValue, isCascadeDeleteEnabled, new HashSet<>() );
364+
stage = stage.thenCompose( v -> ( (ReactiveSession) eventSource )
365+
.reactiveRemove( entityName, loaded, isCascadeDeleteEnabled, new IdentitySet() ) );
366366
}
367367
}
368368
}

hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/ReactiveSession.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public interface ReactiveSession extends ReactiveQueryExecutor {
6060

6161
CompletionStage<Void> reactiveRemove(Object entity, boolean isCascadeDeleteEnabled, IdentitySet transientObjects);
6262

63+
CompletionStage<Void> reactiveRemove(String entityName, Object child, boolean isCascadeDeleteEnabled, IdentitySet transientEntities);
64+
6365
<T> CompletionStage<T> reactiveMerge(T object);
6466

6567
CompletionStage<Void> reactiveMerge(Object object, MergeContext copiedAlready);

hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/impl/ReactiveSessionImpl.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,24 @@ public CompletionStage<Void> reactiveRemove(Object object, boolean isCascadeDele
741741
null,
742742
object,
743743
isCascadeDeleteEnabled,
744-
((ReactivePersistenceContextAdapter) getPersistenceContextInternal())
744+
( (ReactivePersistenceContextAdapter) getPersistenceContextInternal() )
745+
.isRemovingOrphanBeforeUpates(),
746+
this
747+
),
748+
transientEntities
749+
);
750+
}
751+
752+
@Override
753+
public CompletionStage<Void> reactiveRemove(String entityName, Object child, boolean isCascadeDeleteEnabled, IdentitySet transientEntities) {
754+
checkOpenOrWaitingForAutoClose();
755+
756+
return fireRemove(
757+
new DeleteEvent(
758+
entityName,
759+
child,
760+
isCascadeDeleteEnabled,
761+
( (ReactivePersistenceContextAdapter) getPersistenceContextInternal() )
745762
.isRemovingOrphanBeforeUpates(),
746763
this
747764
),

0 commit comments

Comments
 (0)