spring-projects / spring-projects/spring-data-relational
Investigate improvement of Set handling [DATAJDBC-300]
@schauder is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 827
- Forks
- 394
- PR merge metrics
- No merged PRs in 30d
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.