簡體   English   中英

在JPA中更新一對一關系

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM