spring+hibernate實體類註解詳解(非原創) + cascade屬性取值
阿新 • • 發佈:2019-02-16
//User實體表示使用者,Book實體表示書籍,為了描述使用者收藏的書籍,可以在User和Book之間建立ManyToMany關聯 @Entity public class User { private List books; @ManyToMany(targetEntity=package.Book.class) public List getBooks() { return books; } public void setBooks(List books) {this.books=books; } } @Entity public class Book { private List users; @ManyToMany(targetEntity=package.Users.class, mappedBy="books") public List getUsers() { return users; } public void setUsers(List users) { this.users=users; } }