我有以下具有以下关系的实体:
@Entity
@Table(name = "bpr_user")
public abstract class User {
...
@OneToOne(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.REMOVE})
@JoinColumn(name = "bcard_id", nullable = true)
public BCard getBcard() {
return bcard;
}
}
当我像这样运行合并时:
Adult adult = new Adult();
BCard bcard = createBCard();
adult.setBcard(bcard);
adult = adultDao.merge(adult);
Bcard 实体被持久化并被赋予一个 id,但如果我使用 saveOrUpdate,只有 Adult 被持久化,而不是 Bcard。为什么??
Adult adult = new Adult();
BCard bcard = createBCard();
adult.setBcard(bcard);
adult = adultDao.saveOrUpdate(adult);