您好,我得到以下实体类的书:
$

@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中的配置文件仍然为空。我究竟做错了什么 ?

最佳答案

您需要在MERGE字段的级联类型中添加bookProfile

10-06 02:33