diff --git a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactiveDeleteEventListener.java b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactiveDeleteEventListener.java index fbb98a7e2..971c3b722 100644 --- a/hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactiveDeleteEventListener.java +++ b/hibernate-reactive-core/src/main/java/org/hibernate/reactive/event/impl/DefaultReactiveDeleteEventListener.java @@ -339,59 +339,55 @@ protected CompletionStage deleteEntity( persistenceContext.setEntryStatus( entityEntry, Status.DELETED ); final EntityKey key = session.generateEntityKey( entityEntry.getId(), persister ); - CompletionStage beforeDelete = cascadeBeforeDelete( session, persister, entity, entityEntry, transientEntities ); - - CompletionStage nullifyAndAction = new ForeignKeys.Nullifier( - entity, - true, - false, - session, - persister - ).nullifyTransientReferences( entityEntry.getDeletedState() ) - .thenAccept( v -> { - new Nullability( session ).checkNullability( - entityEntry.getDeletedState(), - persister, - Nullability.NullabilityCheckType.DELETE - ); - persistenceContext.registerNullifiableEntityKey( key ); - - ReactiveActionQueue actionQueue = actionQueue( session ); - - if ( isOrphanRemovalBeforeUpdates ) { - // TODO: The removeOrphan concept is a temporary "hack" for HHH-6484. This should be removed once action/task - // ordering is improved. - actionQueue.addAction( - new ReactiveOrphanRemovalAction( - entityEntry.getId(), - deletedState, - version, - entity, - persister, - isCascadeDeleteEnabled, - session - ) - ); - } - else { - // Ensures that containing deletions happen before sub-deletions - actionQueue.addAction( - new ReactiveEntityDeleteAction( - entityEntry.getId(), - deletedState, - version, - entity, - persister, - isCascadeDeleteEnabled, - session - ) - ); - } - } ); - - CompletionStage afterDelete = cascadeAfterDelete( session, persister, entity, transientEntities ); - - return beforeDelete.thenCompose( v -> nullifyAndAction ).thenCompose( v -> afterDelete ); + return cascadeBeforeDelete( session, persister, entity, entityEntry, transientEntities ) + .thenCompose( v -> new ForeignKeys.Nullifier( + entity, + true, + false, + session, + persister + ).nullifyTransientReferences( entityEntry.getDeletedState() ) + .thenAccept( vv -> { + new Nullability( session ).checkNullability( + entityEntry.getDeletedState(), + persister, + Nullability.NullabilityCheckType.DELETE + ); + persistenceContext.registerNullifiableEntityKey( key ); + + ReactiveActionQueue actionQueue = actionQueue( session ); + + if ( isOrphanRemovalBeforeUpdates ) { + // TODO: The removeOrphan concept is a temporary "hack" for HHH-6484. This should be removed once action/task + // ordering is improved. + actionQueue.addAction( + new ReactiveOrphanRemovalAction( + entityEntry.getId(), + deletedState, + version, + entity, + persister, + isCascadeDeleteEnabled, + session + ) + ); + } + else { + // Ensures that containing deletions happen before sub-deletions + actionQueue.addAction( + new ReactiveEntityDeleteAction( + entityEntry.getId(), + deletedState, + version, + entity, + persister, + isCascadeDeleteEnabled, + session + ) + ); + } + } ) ) + .thenCompose( v -> cascadeAfterDelete( session, persister, entity, transientEntities ) ); } private ReactiveActionQueue actionQueue(EventSource session) {