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

How come Spring Data Rest only allows updates from the owner side of ManyToOne/ManyToMany? [DATAREST-1449]

Open
#1,810 0 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

gigecogary opened DATAREST-1449 and commented

I downloaded a sample project from here https://www.baeldung.com/spring-data-rest-relationships

I then ran it and did some test REST calls. As far as I can tell you can only update association from the owner side using SDR. What I mean is

public class Book { @ManyToOne @JoinColumn(name = "library_id") private Library library; }

and

public class Library { @OneToMany(mappedBy = "library") private List<Book> books; }

You can't actually make post/put calls to /libraries/1/books. Server return 204 but no effect on the db whatsoever.

You can however, make post/put calls to /books/1/library and everything works as intended including keeping the other entity in sync.

Is this normal? It's the same behaviour for @ManyToMany as well. Is there a way to allow for updates from both sides? If I write my own API I can certainly make this the case. Why does SDR not do this?


Affects: 3.2 GA (Moore)

Reference URL: https://stackoverflow.com/questions/58685582/how-come-spring-data-rest-only-allows-updates-from-the-owner-side-of-manytoone-m

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.