During a merge, the CollectionType#replaceElements method calls clear on the target object:
But, in certain situations, the target is a PersistentSet wrapping the original collection, so when clear is called, the original collection gets cleared as well, so all the elements collections will be deleted.
The attached test case proves the issue.
To see the problem, add a breakpoint at this line:
And then, add another breakpoint in the replaceElements method of the CollectionType.
On the 8th call of that breakpoint, we get the following objects:
Now, the problem is that target is basically rapping the original collection:
And, for this reason, the collection will be deleted, even if it should have been merged with the new data:
Do you think this could be related to ?