-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Removing association does'nt delete rec. (cascade set.......
PostPosted: Thu Nov 17, 2005 4:25 pm 
Newbie

Joined: Thu Nov 10, 2005 3:11 pm
Posts: 8
Hibernate 3.0.5:

Below is a mapping for an entity Element Usages:

<hibernate-mapping
package="gov.nysed.vrc.domain" schema="EAD">

<class name="ElementUsage" table="ELEMENT_USAGES" lazy="true">

......... . . . . . . ................ . . .. ............

<property name="modifiedBy" length="40" column="MODIFIED_BY"/>

<many-to-one name="elementTemplate" class="ElementTemplate" column="ELTMPL_ID" not-null="true"></many-to-one>
<many-to-one name="parentElementUsage" class="ElementUsage" column="ELUSG_ID" ></many-to-one>

<set name="elements" table="ELEMENTS" inverse="true" cascade="all-delete-orphan">
<key column="ELUSG_ID"/>
<one-to-many class="Element"/>
</set>
<set name="childElementUsages" table="ELEMENT_USAGES" inverse="true" cascade="all-delete-orphan">
<key column="ELUSG_ID"/>
<one-to-many class="ElementUsage"/>
</set>

</class>

</hibernate-mapping>



We have a table ELEMENT_USAGES which has a recursive Parent/Child relationship. Basically it is a Tree... As you can see from the mapping there are 2 objects (parentElementUsage and childElementUsages) which represent the parent/child relationship.

Issue: Below is the code I tried to use to delete a child record -

ElementUsage elementUsage = (ElementUsage) dc.getNodeObject();
AbstractVRCDAO.attach(elementUsage, false);

// after creating childElementUsage from page

elementUsage.removeChildElementUsages(childElementUsage);
addMessage("data.record.deleted", new String[]{childElementUsage.getElementTemplate().getTagName()}, request);


Here, the 'attach' method is nothing but a call to Session.lock(). 'removeChildElementUsages' removes the object from the Set. It does return 'true' but still it does not remove from the db. I am using the session-per-request pattern (using Filter), so the session is available for the entire request.

I had to force the delete operation by calling delete. On the other hand, using the similar code I was able to delete the 'ELEMENTS' set (declared in the mapping file) without calling the delete method. Both collections have the same Cascade settings, why doesn't the 'childElementUsages' get deleted but the 'elements' gets deleted. Any help would be appreciated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.