我有以下具有以下关系的实体:
@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);