[英]Update one-to-one relation in JPA
你好,我得到了以下實體類書:$
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@OneToOne(cascade=CascadeType.PERSIST)
private BookProfile bookProfile;
@OneToMany(cascade=CascadeType.PERSIST , orphanRemoval=true, fetch=FetchType.EAGER)
private List<Rating> ratings;
$
我嘗試添加這樣的配置文件:
$
Book book = manager.find(Book.class, bId);
BookProfile bookProfile = new BookProfile();
manager.getTransaction().begin();
book.setBookProfile(bookProfile);
manager.merge(book);
manager.getTransaction().commit();
$
但沒有任何事情發生在Book中的配置文件仍為null。 我究竟做錯了什么 ?
您需要將MERGE
添加到bookProfile
字段的級聯類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.