spring-projects / spring-projects/spring-data-rest
Issue when updating a @OneToMany collection resource with a nested @ManyToOne/@OneToOne resource - PUT/PATCH
@odrotbohm is already working on this.
Since Jan 31, 2025.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Spring Boot version: 3.3.2
After upgrading to Spring Boot 3, we have noticed an issue when trying to update a collection resource via the PUT and PATCH endpoints provided by Spring Data REST on a @RepositoryRestResource. When trying to update a @OneToMany collection element that has a nested @ManyToOne/@OneToOne resource, the nested resource is not being persisted correctly back to the database.
- Adding new elements to the
@OneToManycollection works fine with POST, PUT and PATCH. Nested resources are mapped correctly. - Updating the nested resource of an existing element in the
@OneToManycollection does not update the nested resource. - Removing an element from the
@OneToManyresource where the element isn't the last in the collection, causes all the elements after to shift up an index (which is correct) but doesn't accordingly carry their nested resource up with them, resulting in all the elements after the one being removed to have the wrong nested resources.
Please have a look at this example project which shows the setup that we have, along with a test class that will help demonstrate the issue.
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.