Description
Jens Schauder opened DATAJDBC-300 and commented
As described in this Stackoverflow question entities with a broken equals/hashcode contract trigger unexpected behavior when included in Sets since instances end up twice in the Set after saving.
What happens internally is the following: the Person entity gets saved. This might or might not create a new Person instance if Person is immutable.
Then the Address gets saved and thereby gets a new id which changes it's hashcode. Then the Address gets added to the Person since again it might be a new Address instance.
But it is the same instance yet now with a changed hashcode, which results in the single set containing the same Address twice.
Options to mitigate this are:
- setting the complete set instead of single elements (would also work better when the parent instance is immutable.
- removing the old instance before adding the new one
No further details from DATAJDBC-300