2012-10-09 2 views
2

나는 최대 절전 모드 매핑을 상속 받았으며 하나의 부모 노드에서 다른 노드 노드로 자식 노드를 이동하는 데 문제가있다. 중복 참조를 얻거나 오류가 발생합니다.자식 이동시 Hibernate 콜렉션이 업데이트되지 않는다.

위치가 나무에 있습니다. 한 잎 노드를 다른 잎 위치로 옮기고 싶습니다.

GeographicLocation oldParent = location.getParent(); 
location.setParent(newParent); 
newParent.getChildren().add(location); 
oldParent.getChildren().remove(location); 

원인 : 코드에서 나는이 할 노력하고있어

org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.test.GeographicLocation#11] 
내가 선 oldParent.getChildren().remove(location)newParent 노드가 제대로 아이에게 포인트를 제거하면

하지만 oldParent 여전히에 대한 참조가 아이도 (!). 최대 절전 모드 설정 파일에서

조각 : 나는 매우 긴 최대 절전 모드를 사용하지 않은

<class name="GeographicLocation" table="GeographicLocation"> 
    <id column="GeographicLocationId" name="geographicLocationId" type="java.lang.Long"> 
    <generator class="native"> 
     <param name="sequence">GeographicLocationId</param> 
    </generator> 
    </id> 

<many-to-one class="com.test.GeographicLocation" 
    foreign-key="ParentFK" name="parent"> 
    <column name="parent"/> 
</many-to-one> 

<bag cascade="all,delete-orphan" inverse="true" lazy="false" name="children"> 
    <key column="parent" not-null="true"/> 
    <one-to-many class="com.test.GeographicLocation"/> 
</bag> 

. 내 이해는 location 노드가 관리 객체이므로 수정시 자체를 저장한다는 것입니다. 최대 절전 모드 설정 파일이 cascade=all으로 지정되어 있기 때문에 컬렉션에 대한 변경 사항 또한 하위 변경 사항을 저장합니다. 그러나 이전 참조를 제거 할 합법적 인 방법을 찾을 수 없습니다. 어떤 도움이 필요합니까?

+0

중복 된 것으로 보입니다. http : //stackoverflow.com/questions/11649249/deleted-object-would-be-re-saved-by-cascade-remove-deleted-object-from-associat – dan

답변

1

매핑에서 delete-orphan을 제거 하겠지만, 컬렉션에서 요소를 제거하자 마자 제거해야합니다 (분명히 원하는 것은 아닙니다).

관련 문제