0
Iエンティティ、oneToMany関係に取り組んできましたが、問題は、私はこれを使用するときということです:@PreUpdate注釈の代わりにEclipseリンク?
//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を更新し、エンティティ、親werenのID」を更新し、特にクリーン子エンティティと一緒に(外部キーとして)保持されます。助けてください...
@PreUpdateが動作していないようです、@PrePersistは完全に動作します。
私は、アップデートをクリーンなものにしないことで管理しました。つまり、parentIDを設定せず、@PreUpdateにch.setParent(this)を設定することです。 @PreUpdateは、あなたが逆参照しておらず、あなたの子エンティティをもう一度参照しない場合にはうまくいくようです。ありがとう、しかし! –