I am trying to delete an entity that has a self reference to itself and i get the following error. I am using hibernate 3 and this functionality was working well in the older version of hibernate 2
deleted object would be re-saved by cascade (remove deleted object from associations): [com.entity.ReferralEntity#5911]
at org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at com.iso.scm.util.HibernateRequestProcessor.process(HibernateRequestProcessor.java:55)
Table Mapping
1) ObjectA - Maps to TableA
2) ObjectB - Maps to TableB
Class structure
Code:
public class ObjectA
{
private ObjectB objB;
}
public class ObjectB
{
private List objB1; // List contains object of type ObjectB
private List objB2; // List contains object of type ObjectB
}
Hibernate Mapping for OjectB Code:
<list name="objB1" table="TableB" fetch="join" cascade="all" lazy="false" where="C_ENTY_TYP = '0003'">
<key column="I_PRNT_CASE_ENTY"/>
<list-index column="I_REFR_ENTY"/> --- The key which link it ObjectA
<one-to-many class="ObjectB" />
</list>
<bag name="objB2" where="C_ENTY_TYP = '0002'" table="TableB" fetch="join" cascade="all" lazy="false">
<key>
<column name="I_PRNT_CASE_ENTY"/>
</key>
<one-to-many class="ObjectB" />
</bag>
Quote:
When i delete(objectA) i.e deleteing ObjectA, i expect all the child objects (ObjectB) to get deleted as well, but instead i get the above error. I did search a bit and tried removing objB from ObjectA but that would leave the child Objects of objB,B1,B2 as it is. Please let me know as to how i can achieve the above scenario. I am struggling with this for a while...i almost gave up and looking up for someone to guide me.
Thanks in Advance!!!
Zieus