【发布时间】:2020-01-10 13:51:22
【问题描述】:
我在两个类之间有这样的关系:
Smartlist -> smartlistId`是PK
AccountEmailing -> smartlistId FK,PK
AccountEmailing 表可能没有初始引用记录,但后来它可能有记录
我只使用 smartlist 表存储库
我试过cascade.ALL,但在 FK 表 id 中得到了 null
我已尝试使用以下组合的以下代码,
smartlist和AccountEmailing的初始数据
这很有效
带有智能列表的初始数据,AccountEmailing 中没有数据
意味着它不会在 AccountEmailing 中创建条目,但稍后会添加一条记录,它会为 AccountEmailing 创建一个插入语句,并且从下次开始它总是会更新
我正在寻找一种解决方案,如何更新我的课程以便我可以在 AccountEmailing 上执行 CRUD:
public class Smartlist {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "smartlistId")
private Integer smartlistId;
@OneToOne( mappedBy = "smartlist", fetch = FetchType.LAZY, cascade = CascadeType.PERSIST, orphanRemoval = true)
private AccountEmailing accountEmailing;
}
@Entity
@Table(name = "account_emailing")
public class AccountEmailing implements Serializable {
@Id
@OneToOne
@JoinColumn(name = "smartlistId")
private Smartlist smartlist;
}
【问题讨论】:
-
看看这个如果有帮助。你需要@MapsId stackoverflow.com/questions/59282221/…
-
*我试过下面的代码*:哪个代码?发布代码,准确说明您希望它做什么,以及它会做什么。