我有如下两张表,问题是每本书只能由一个人拥有。
Person_ID Book_ID
1 1 <<correct
2 1 << ERORR
如何改变它以使每本书可以被很多人拥有?
人.java
@Entity
public class Person {
private long id;
.....
@OneToMany(cascade = CascadeType.ALL)
public Set<Book> getBooks() {
return books;
}
....
}
图书.java
@Entity
public class Book {
private long id;
....
}