spring-projects / spring-projects/spring-data-rest

Concurrency issue with JPA Lists [DATAREST-895]

Open
#1,264 6 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Laurent Bovet opened DATAREST-895 and commented

I have a OneToMany association with a JoinTable:
https://github.com/lbovet/bugtik/blob/jointable-concurrency-issue/src/main/java/li/chee/bugtik/Project.java#L20

When creating associations in parallel (POST URIs to the collection resource concurrently), There is a race condition where the previous collection content overwrites a more recent one. This results in not all the associations created.

Note that if I model the association with a JoinColumn, the problem does not arises:
https://github.com/lbovet/bugtik/blob/joincolumn-concurrency-ok/src/main/java/li/chee/bugtik/Project.java#L20

I think it is a bug that Spring Data Rest operations are not performed atomically in the JoinTable case. If not, is there a configurative way to solve this?

You can checkout the sample project (https://github.com/lbovet/bugtik.git) and try both branches:
mvn spring-boot:run
http://localhost:8080/concurrency-test.html


Affects: 2.4.4 (Gosling SR4), 2.5.2 (Hopper SR2)

Reference URL: https://github.com/lbovet/spring-data-rest/tree/issue/DATAREST-895

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.