0

I am working with Spring Boot JPA. I have a model for Authors and Books:

In Author.java

@ManyToMany
@JsonIgnore
@JoinTable(
        name = "authors_write",
        joinColumns = @JoinColumn(name = "author_id"),
        inverseJoinColumns = @JoinColumn(name = "book_id"))
Set<Book> works;

Book.java

In Book.java

@ManyToMany(mappedBy = "works")
@EqualsAndHashCode.Exclude
Set<Author> authors;

and when inserting (via postman for example) data into Book table with an Author Object entries do not get updated.

How do I insert data into authors_write when posting into Book table?

A Y
  • 109
  • 3
  • 12

1 Answers1

1

Since I can only answer and not comment here it goes. You'll still need to set the book to the author

author.setBook(book)

Check out Vlad Mihalcea's blog on just about anything dealing with Hibernate.

https://vladmihalcea.com/blog/

Another good one is Thorben Janssen

https://thoughts-on-java.org/blog/

  • This worked. I called the Author by the ID, called `author.getWorks().add(book)` and the problem was solved. I did not update the author instance, that deleted all entries of the author in authors_write – A Y Apr 30 '20 at 18:30