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

POSTing to Entity with ManyToMany(JoinTable) association resource [DATAREST-830]

Open
#1,203 1 comment 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

Bharath Kumar Ramasubramanian opened DATAREST-830 and commented

I have the following entities
@Entity
@Table(name = "book")
public class Book implements java.io.Serializable {
.....
@ManyToMany(fetch = FetchType.LAZY,cascade=CascadeType.ALL)
@JoinTable(name = "book_author_link", joinColumns = { @JoinColumn(name = "BOOKID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "AUTHORID", nullable = false, updatable = false) })
private Set<Author> authors;
.....
}

@Entity
@Table(name = "author")
public class Author implements java.io.Serializable {

//No back reference to Book(Keeping it uni-directional)
}

I want to create Book and Author's separately so I have separate repositories for both of them.
Say, first I have created an author and have its URI. Now when I want to create a Book (using POST-with its other fields), how do I pass the author URI. If author is OneToOne mapping resource, I can directly pass the URI and it would work, but here it is a many-to-many.

Is the only way here is to create a Book element(using POST and json) with all its fields (except Author) first and then use the "PATCH and text/uri" to add the author?


No further details from DATAREST-830

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.