我有一个父母,一个孩子和一个孙子对象。问题是,当我在应用程序中删除孙子项并保存父对象时,孙子项更改不会被更新。
家长班
@OneToMany(fetch = FetchType.EAGER, mappedBy = "parent")
@ForeignKey(name = "FK_1")
@Cascade({CascadeType.ALL})
private Set<Child> children;
儿童班
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "parent")
@XmlTransient
private parent parent;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "child")
@ForeignKey(name = "FK_2")
@Cascade({CascadeType.ALL})
private Set<GrandChild> grandchildren;
在大童班
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "child", nullable = false)
@XmlTransient
private Child child;
我使用休眠4.2.2.Final。
任何的想法?
尝试将orphanRemoval添加到您的收藏中。
@OneToMany(fetch = FetchType.EAGER, mappedBy = "parent", orphanRemoval=true)
@OneToMany(fetch = FetchType.EAGER, mappedBy = "child", orphanRemoval=true)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句