I am using hibernate 3 and I have a category object mapped with the hibernate mapping included at the bottom of this post
It has among others the following methods :
public void removeChildCategory(Category category){
if (category == null) {
throw new IllegalArgumentException("Category to be removed from category is null");
}
category.setParentCategory(null);
childCategories.remove(category);
}
public void addChildCategory(Category category){
if (category == null) {
throw new IllegalArgumentException("Category to be added to category is null");
}
category.setParentCategory(this);
childCategories.add(category);
}
The problem is that when i try to move one category to another
like this
Code:
booksCat.removeChildCategory(thrillersCat);
moviesCat.addChildCategory(thrillersCat);
I get the following exception
org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.zenggi.data.Category#379]
I am kind of at a loss as to why this is occuring since the parent field has cascade set to none and the item got removed from the first collection
can anyone offer some insight ?
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.company">
<class name="Category"
table="CATEGORY"
lazy="true">
<id name="id"
type="long"
column="ID"
unsaved-value="null">
<generator class="identity"/>
</id>
<version name="version" column="VERSION" type="integer"/>
<property name="name" type="string">
<column name="NAME" not-null="true"/>
</property>
<property name="description" type="string">
<column name="DESCRIPTION" />
</property>
<many-to-one name="parentCategory"
class="Category"
lazy="false"
insert="false"
update="false"
cascade="none">
<column name="PARENT_CATEGORY_ID"
not-null="false" />
</many-to-one>
<list name="childCategories"
lazy="false"
cascade="all-delete-orphan"
inverse="false">
<key column="PARENT_CATEGORY_ID"/>
<list-index column="CATEGORY_INDEX" />
<one-to-many class="Category"/>
</list>
</class>
</hibernate-mapping>