0
@Entity
public class Parent {
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
int id;
@OneToMany(cascade=CascadeType.REMOVE)
List<Item> children = new ArrayList<Child>();
}
@Entity
public class Child {
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
int id;
}
上記のように、私は親と子の間にOneToMany-Relationを持っています。親のインスタンスを削除すると、すべての子も削除されます。これを他の方法でも有効にする方法はありますか?JPA:逆カスケード削除
Parent p = new Parent();
Child c = new Child();
p.children.add(c);
EntityManager.persist(p);
EntityManager.persist(c);
EntityManager.remove (c);
このコードは例外なく実行されますが、次回にpをロードすると新しい子が添付されます。