0
我一直在工作的實體,一對多的關係,問題是,每當我用這個:Eclipse鏈接替代@PreUpdate註釋?
//Parent class
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER,
targetEntity = FeedbackCategory.class, mappedBy = "parent")
@PrivateOwned
@OrderBy("category ASC")
private List<Child> children;
//... other code here, i.e. getters-setters
@PrePersist
@PreUpdate
void prePersistUpdate() {
// set the foreign key of child to this.ID
if(children != null && !children.isEmpty())
{
for(Child ch: children)
{
ch.setParent(this);
}
}
}
更新Parent.class時,尤其是當清潔更新實體,家長間沒有的ID」 t與子實體一起堅持(作爲外鍵)。請幫助...
看起來@PreUpdate不起作用,@PrePersist完全起作用。
我想通過不更新一個乾淨的(也就是說,沒有設置parentID並在@PreUpdate上設置ch.setParent(this))來管理它。如果您不會取消引用並再次引用您的子實體,那麼@PreUpdate似乎正在工作。不過謝謝! – 2012-04-12 01:38:25