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