2014-04-24 2 views
0

아이들을 삭제JPA : 나는 아래로 OneToMany 매핑이 OneToMany

부모 :

@OneToMany(mappedBy = parent, orphanRemoval = true, cascade = { CascadeType.ALL}) 
private List<Child> childs = new ArrayList<Child>(); 

아이 :

@ManyToOne 
@JoinColumn(name = "parentid") 
private Parent parent; 

부모 개체를 업데이트하는 동안, 나는 예외를 얻고있다 :

A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance 

코드 :

parent.getChild().clear(); 
parent.setChild(childList) 

답변

0

당신은 부모로부터 자식을 제거 할 수 있지만 Child가 소유 측이기 때문에, 당신은 Child 기관에서 Parent에 대한 참조를 제거해야합니다.

for (Child child: children) { 
    child.setParent(null); 
}