親が保存または永続化されているときに子を保存または永続化させたくないため、カスケード「削除」(jpa) および「delete-orphan」を使用して 1 対多の関係をマップしようとしています (セキュリティ上の理由によるクライアントからサーバーへ (GWT、Gilead))
しかし、この構成は機能しません。カスケード「すべて」で試してみると、実行されます。delete-orphan オプションを実行するためにカスケード "all" が必要なのはなぜですか?
コードは次のとおりです (簡単にするために id やその他のフィールドはありません。クラス Thread は、カスケードなしで単純な多対 1 のプロパティを定義します):removeThread
トランザクション関数で関数を使用すると実行されませんが、編集cascade.Remove
するcascade.All
と実行されます。 .
@Entity
public class Forum
{
private List<ForumThread> threads;
/**
* @return the topics
*/
@OneToMany(mappedBy = "parent", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
public List<ForumThread> getThreads()
{
return threads;
}
/**
* @param topics the topics to set
*/
public void setThreads(List<ForumThread> threads)
{
this.threads = threads;
}
public void addThread(ForumThread thread)
{
getThreads().add(thread);
thread.setParent(this);
}
public void removeThread(ForumThread thread)
{
getThreads().remove(thread);
}
}