Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Problem with Delete and cascade in Hibernate

  Asked By: Harley    Date: Dec 13    Category: Java    Views: 2773

I have a table named REQUIRMENTS , i gave this exception when i want to delete a record :

nested exception is org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations)

the hbm.xml file is :
<many-to-one name="parent" cascade="none">
<column name="REQ_PARENT_ID" not-null="false"/>
<bag name="children" cascade="all-delete-orphan" inverse="true" lazy="true" batch-size="10">
<key column="REQ_PARENT_ID"/>
<one-to-many class="com.navaco.model.project.Requirement" not-found="ignore"/>

<list name="preRequirements"
<key column="PRQ_REQ_REFRENCE"/>
<list-index column="PRQ_ID"/>
<property name="percentage" column="PRQ_PERCENTAGE" type="float"/>
<many-to-one class="com.navaco.model.project.Requirement" name="refered" column="PRQ_REQ_REFERED"/>

I think i have done every thing write , dose any body know what is the problem ??



1 Answer Found

Answer #1    Answered By: Tyrone Sanchez     Answered On: Dec 13

look!you use [inverse="true"] and cascade is "all-delete-orphan";
so when you want to remove  the class,it wants to remove its childs because af cascade,but you mentioned inverse=true,it means it couldnt be removed,because you sholud be aware of the cascade and coulmn in oppsoit side mapping(com.navaco.model.project.requirement.hbm.xml);

Didn't find what you were looking for? Find more on Problem with Delete and cascade in Hibernate Or get search suggestion and latest updates.