I have a list of Agent2User entities as the N side of a 1-N relation that also updates the 1 side by calling the setter. This could cause a loop, but the contains-remove setup below breaks that: if the entity is still in the list, remove it, then call the setter, which will then call the remove again, but the entity will not be in the list anymore and thus the loop breaks.

The code is below and there 5 debug lines mixed in (the actual method is only 3 lines).

Explanation:
1. The method enters and the list reports a size of 1, the objects appear to be equal.
2. The if condition passes, so contains must have returned true.
3. The remove is executed and WasRemoved is true.
4. Then it turns out the list is NOT of size zero and the entity is still present!!!

How can this be?

I tried to reproduce this in a standalone example, but I cannot. This only happens if the entity is returned via a SOAP interface. That doesn't solve my problem though.

> My guess is you have two copies of the source object. Try printing the
> source object as well.
>
> i.e.
> Agent->Agent2User->Agent'
>
> Seems like you corrupted your object with multiple copies, you may be
> missing a merge somewhere.

Aside from that my problem is gone now; the debug output printed the memory address of the object (@5366ef) and both were identical. The contains and remove were done on the same list in the same method. IF it passed "contains" then it should have been removed. Right?