I have met a bug with cascade remove that I managed to reproduce with this use case (see also the diagram in the attachments):
- User has many Roles
- Roles has many Authorization
- User has also many Authorization (cache of all authorizations of all roles)
All these associations are bidirectional, and with "cascade remove".
When I remove User:
- User cascade remove on Role
- Role cascade remove on Authorization
- User cascade remove on Authorization
If collections are lazy-loaded, then step 1. will clear the roles from the identityMap, but step 3. will reload the roles (because the authorizations will be lazy-loaded) and re-insert them in the identityMap.
As a consequence, the first flush() succeeds, but any further flush() yields:
I am creating a PR with a testcase, and probably a fix.