我有以下实体
@Entity
public class Note {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "NOTE_ID")
private long id;
//bi-directional many-to-one association to book
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "BOOK_ID", referencedColumnName = "BOOK_ID" )
private Book book;
}
@Entity
public class Book{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "BOOK_ID")
private long id;
//bi-directional one-to-many association to note
@OneToMany( mappedBy="book", cascade = { CascadeType.ALL }, fetch = FetchType.LAZY )
private List<Note> notes;
}
我想知道的是
有人说,从双方更新双向关系是不好的。原因是什么?
如果我想更新双方的关系,我该怎么做?使用这种格式,当我从书本实体添加一个“注解”时,注解实体中的数据被保存,但没有书本id。如何排列设置器以便能够从两端保存?
先谢谢你
暂无答案!
目前还没有任何答案,快来回答吧!