spring-projects / spring-projects/spring-data-relational

Investigate improvement of Set handling [DATAJDBC-300]

Open
#524 0 comments 0 reactions 1 assignee View on GitHub

@schauder is already working on this.

Since Dec 31, 2020.

in: core type: enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.