我从很多天开始收到一个Hibernate异常,但我无法解决它。可能有人可以帮助我吗?
我有3个休眠实体。 (KainInka,Pvv,Pvt)。
kainInka-> pvv(一对多) pvv-> kainInka(多对一)
pvv-> pvt(一对多) pvt-> pvv(多对一)
我在我的实体类中定义了以下方法:
1.kainInka
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY, mappedBy = "p301KainInkaId")
@OnDelete(action = OnDeleteAction.CASCADE)
public List<TP301KainInkaPvv> getKainInkaPvvs() {
return this.kainInkaPvvs;
}
public void setKainInkaPvvs(final List<TP301KainInkaPvv> kainInkaPvvs) {
this.kainInkaPvvs = kainInkaPvvs;
}
2.PVV实体类:
@ManyToOne(fetch = FetchType.LAZY)
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "T_P301_KAIN_INKA_ID", nullable = false, foreignKey = @ForeignKey(name = "FK_PVV4T_P301_KAIN_INKA_ID"))
public TP301KainInka getP301KainInkaId() {
return p301KainInkaId;
}
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY, mappedBy = "p301KainInkaPvvId")
@OnDelete(action = OnDeleteAction.CASCADE)
public List<TP301KainInkaPvt> getKainInkaPvts() {
return this.kainInkaPvts;
}
public void setKainInkaPvts(final List<TP301KainInkaPvt> kainInkaPvts) {
this.kainInkaPvts = kainInkaPvts;
}
3.Pvt实体类:
@ManyToOne(fetch = FetchType.LAZY)
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "T_P301_KAIN_INKA_PVV_ID", nullable = false, foreignKey = @ForeignKey(name = "FK_PVT4KAIN_INKA_PVV_ID"))
public TP301KainInkaPvv getP301KainInkaPvvId() {
return p301KainInkaPvvId;
}
public void setP301KainInkaPvvId(TP301KainInkaPvv p301KainInkaPvvId) {
this.p301KainInkaPvvId = p301KainInkaPvvId;
}
第一次持久化方法运作完美。
问题在于MERGE方法(kainInkaDao.merge(kainInkaObj);)。我想将新的pvv对象添加到现有的kainInka对象中,并且新的pvv对象具有新的pvt对象。我正在为父(kaininka)对象调用merge方法。所以我认为它应该在数据库中添加新条目,对吧?
但是,它会引发异常: not-null属性引用瞬态值 - 必须在当前操作之前保存瞬态实例:pvv.kainInkaId-&gt; kainInka
我做错了什么或遗漏了一些重点?
非常感谢你!!