-->
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: Hibernate performs delete cascade in wrong order
PostPosted: Fri Jun 06, 2014 6:29 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
My Db is throwing a Constraing violation (FK) because Hibernate performs a cascade delete in the wrong order.

Details: I delete a Member, that has a Wallet with Wallet transactions (value-type), and the wallet transaction has an association to a product just like the Member contains collection of products (see the Hibernate mapping below).

I delete a Member instance, and want Hibernate to remove both the products and Wallet transactions. It seems that it first removes the product instances (through cascading), such that a FK violation is thrown by the DB, as it's still referenced by a Wallet transaction, that wasn't removed yet (through cascade)

I played around with the cascade setting, like all-delete-orphan (on the products), etc..., but no luck I also emptied the wallet transactions and flushed the hibernate session in the same removal transaction, but also the same error.

Please some understanding and help to get the order of cascade deletion correct?

The hibernate mapping (I left out the none-important parts like PK and properties):

Code:
<class name="Member" table="mem" >
<component name="wallet" class="Wallet">
  <set name="transactions" table="wallet_tx" cascade="all">
   <cache usage="read-write" />
   <key column="idTaxer" not-null="true" />
   <composite-element class="WalletTransaction">
    <property name="amount" type="big_decimal" column="amount" />
    <many-to-one name="product" column="idPrdInst" class="Product" cascade="none" />
   </composite-element>
  </set>
</component>

<set name="products"  cascade="delete" inverse="true">
  <key column="idTaxer" not-null="true" />
  <one-to-many class="Product" />
</set>
</class>

<class name="Product" table="prd" >
...
<many-to-one name="member" column="idMember" class="Member" cascade="none" />
</class>

The DB error:
Code:
ERROR:  update or delete on table "prd" violates foreign key constraint "fk_1umej7" on table "wallet_tx"
DETAIL:  Key (id)=(75bef42fc4544) is still referenced from table "wallet_tx".


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.