-->
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.  [ 5 posts ] 
Author Message
 Post subject: cascade="all-delete-orphan" problem
PostPosted: Mon Oct 16, 2006 4:52 pm 
Newbie

Joined: Mon Oct 16, 2006 4:19 pm
Posts: 4
The problem I'm having is as follows:

I basically have class mapping, class B (a subclass of class A), that maps a set of another mapped class, class C into the class B. When I delete class B using Hibernate's Session.delete() I want all of the class C's to be deleted as well. I am using cascade="all-delete-orphan" in the set mapping.

I've tested things and I see the following behavior.

When I comment out the mapped set for class C and I do a delete on class B, I see the following SQL:

delete from BUY where BUY_ID=?
delete from ORDERS where ID=?

Just what I want. But then when I uncomment the set for class C and try to do the same delete, instead of Session.delete() doing a SQL DELETE it actually does an UPDATE and tries to set certain fields to NULL. This creates a UNIQUE constraint problem and I really need DELETE to be called. The SQL looks like:

update LOGIN_RULE set CAMPAIGN_ID=null where CAMPAIGN_ID=?

Which generates an exception:

16:49:40,780 DEBUG JDBCExceptionReporter:63 - Could not execute JDBC batch update [update LOGIN_RULE set CAMPAIGN_ID=null where CAMPAIGN_ID=?]
java.sql.BatchUpdateException: ORA-00001: unique constraint (TEST.UI_LOGIN_RULE_IDS) violated


Anyone know why a call to Session.delete() would be invoking SQL UPDATE statements?

Thanks much,
J


Below are the mappings and other related info.


Hibernate version:
3.2-cr2

Mapping documents:
ObjectFilter.hbm.xml:
-------------------------
<hibernate-mapping>
<class name="com.doubleclick.dart.core.model.impl.ObjectFilterImpl" table="LOGIN_RULE">
<id name="id" column="LOGIN_RULE_ID" type="long" unsaved-value="-1">
<generator class="sequence">
<param name="sequence">LOGIN_RULE_SEQ</param>
</generator>
</id>

<many-to-one name="user" column="LOGIN_ID" class="com.doubleclick.dart.core.model.impl.UserImpl" not-null="true" />
<property name="ruleId" column="RULE_ID" type="long" not-null="true" />
<property name="campaignId" column="CAMPAIGN_ID" type="long" access="field" />
</class>
</hibernate-mapping>


DfaCampaign.hbm.xml:
---------------------------
<hibernate-mapping>
<joined-subclass name="com.doubleclick.dart.dfa.model.impl.DfaCampaignImpl"
extends="com.doubleclick.dart.core.model.impl.OrderImpl" table="BUY">

<key column="BUY_ID" />
<property name="campaignName" column="BUY_NAME_C" type="string" not-null="true" access="field" />

<set name="objectFilters" table="LOGIN_RULE" cascade="all-delete-orphan" >
<key column="CAMPAIGN_ID" />
<one-to-many class="com.doubleclick.dart.core.model.impl.ObjectFilterImpl" />
</set>
</joined-subclass>
</hibernate-mapping>


Order.hbm.xml:
------------------
<hibernate-mapping>
<class name="com.doubleclick.dart.core.model.impl.OrderImpl" table="ORDERS">
<id name="id" column="ID" type="long" unsaved-value="-1">
<generator class="sequence">
<param name="sequence">ORDERS_SEQ</param>
</generator>
</id>

<discriminator column="NAME" type="string" insert="false" />
</class>
</hibernate-mapping>

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle 9i Client Drivers


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 1:57 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Use inverse="true" in your Set 'objectFilters'.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 9:10 am 
Newbie

Joined: Mon Oct 16, 2006 4:19 pm
Posts: 4
I've tried inverse="true" before and just tried again to be sure and that doesn't change anything. It is still trying to do updates instead of deletes.

Also, semantically speaking, as far as I understand inverse="true" this isn't something I want anyway, as I want the campaign end of the mapping to 'drive' want happens to the objectFilters.

Thanks,
Jacob


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 3:52 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
I tried out your mappings with a few minor changes to make it run [in Hibernate 3.1.2] : -
1) commented out UserImpl.
2) commented out discriminator in OrderImpl. Not sure what it is doing here.

On deleting a DfaCampaignImpl with a Set of ObjectFilterImpl I get,

with inverse="false"

Code:
Hibernate: update LOGIN_RULE set CAMPAIGN_ID=null where CAMPAIGN_ID=?
Hibernate: delete from LOGIN_RULE where LOGIN_RULE_ID=?
Hibernate: delete from BUY where BUY_ID=?
Hibernate: delete from ORDERS where ID=?


with inverse="true"

Code:
Hibernate: delete from LOGIN_RULE where LOGIN_RULE_ID=?
Hibernate: delete from BUY where BUY_ID=?
Hibernate: delete from ORDERS where ID=?


(I had to manually set campaignId since you don't have a many-to-one in ObjectFilter)

Not sure why it is not working for you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 11:53 am 
Newbie

Joined: Mon Oct 16, 2006 4:19 pm
Posts: 4
Ah...thanks so much for your help. You led me to the problem. It turned out UserImpl had a reference to something called a UserFilterImpl which in turn mapped in a set of ObjectFilters. Because this set was not also marked with inverse="true" it was screwing things up.

By setting UserFilter's ObjectFilter set mapping and Order's ObjectFilter set mapping to inverse="true", deletes now work as they are supposed to.

Thanks much!


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

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.