The method DbOperationManager#sortByReferences uses the cached entity state to compute the flush ordering. This need not necessarily reflect the state in the database.
Assume a persistent execution structure a <- b <- c
In one transaction:
1. remove b such that new tree is a <- c (can happen when concurrency ends and a concurrent parent is removed)
2. Remove a and c
The above-mentioned method now takes into account the relationship from a <- c, so the relation of c to b is ignored and the flushed DELETEs may be ordered incorrectly
When fixing this, please re-add the failing test cases of