I have two tables as following, the problem is that each book can only be own by one person.
Person_ID Book_ID
1 1 <<correct
2 1 << ERORR
How to change it in a way that each book can be own by many people?
Person.java
@Entity
public class Person {
private long id;
.....
@OneToMany(cascade = CascadeType.ALL)
public Set<Book> getBooks() {
return books;
}
....
}
Book.java
@Entity
public class Book {
private long id;
....
}
You need to change the relationship to ManyToMany
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments