[英]Update one-to-one relation in JPA
Hello i got the following entity class Book: $ 你好,我得到了以下实体类书:$
@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;
$ $
i try to add a Profile like this: 我尝试添加这样的配置文件:
$ $
Book book = manager.find(Book.class, bId);
BookProfile bookProfile = new BookProfile();
manager.getTransaction().begin();
book.setBookProfile(bookProfile);
manager.merge(book);
manager.getTransaction().commit();
$ $
But nothing happens the profile in Book is still null. 但没有任何事情发生在Book中的配置文件仍为null。 What am i doing wrong ?
我究竟做错了什么 ?
您需要将MERGE
添加到bookProfile
字段的级联类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.