Update in-memory collections before dispatching the postRemove
event
#11132
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make sure in-memory collections have removed entities unset before the
postRemove
event is dispatched. This is related to #11098, although by itself probably not going to fix the regression.Background
When an entity is removed from the database, the UoW also takes care of removing that entity from all in-memory collections. #10763 moved this cleanup and taking snapshots of updated collections to a very late stage during the commit phase, in order to avoid other side effects.
Now, part of the issue in #11098 is that
postRemove
event listeners will be called at a point where the database-levelDELETE
has happened (although the transaction has not yet been committed), but the in-memory collections have not yet been updated.Suggested change
This PR moves the code part that unsets removed entities from in-memory collections and takes collection snapshots (makes collections "clean") from after transaction commit to before the
postRemove
event. That brings the in-memory update closer to the database-level execution.In the case of a transaction failure/abort, this leaves us with updated and snapshotted in-memory collections, but no database-level updates. But, at this point, probably things got inconsistent anyways, the EM will be closed and we need not be too worried about the state.
On the other hand, it might not be worth the effort to have clean/consistent collections at
postRemove
time, since that still leaves us with dirty/inconsistent states duringpostPersist
orpostUpdate
.