-->
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.  [ 3 posts ] 
Author Message
 Post subject: cascade delete not iterating more than 3 tables
PostPosted: Wed Apr 25, 2007 4:34 am 
Newbie

Joined: Thu Feb 16, 2006 8:19 am
Posts: 6
I have 4 tables

Customer has one-to many relation with Orders
Orders has many-to-one relation with Customer

Orders has one-to-many relation with LineItem
LineItem has many-to-one relation with Orders

LineItem has one-to-many relation with ItemConf
ItemConf has many-to-one relation with LineItem


all above are bidirectional

table got generated and all foreignkey relations are eastablished correctly.
i am able to insert and select data successfully.

when i try to delete Customer i am getting foreignkey violation exception from ItemConf,

on looking into the Log i found that its trying to delete LineItem rows before deleting from ItemConf.


please give me a solution


Hibernate version:3

Mapping documents:
Customer:
--------------------------------------------------------------------------
<class name="Customer" table="customer">
<id
name="customerId"
type="string"
column="customerId"
/>
<bag name="order" inverse="true" cascade="delete">
<key column="customerId"/>
<one-to-many class="Order"/>
</bag>
</class>
--------------------------------------------------------------------------------
Orders:
<class name="Order" table="orders" >
<id
name="orderId"
type="java.lang.Long"
column="orderId"
>
<generator class="increment"/>
</id>
<many-to-one class="Customer" name="customer" column="customerid" insert="false" update="false" />

<bag name="items" cascade="all" inverse="true">
<key column="orderId"/>
<one-to-many class="LineItem" />
</bag>
</class>
--------------------------------------------------------------------------------
LieItem:

<class name="LineItem" table="lineitem">
<composite-id>
<key-property name="orderId"
column="orderId"
type="java.lang.Long"/>
<key-property name="itemId" column="itemId" type="string"
/>
</composite-id>

<bag name="configurations" cascade="all" inverse="true">

<key>
<column name="itemId"/>
<column name="orderId"/>
</key>
<one-to-many class="ItemConfiguration"/>
</bag>
<many-to-one class="Order" column="orderId" name="Order" insert="false" update="false"/>

</class>
---------------------------------------------------------------------------------
ItemConf:

<class
name="ItemConfiguration"
table="itemconfiguration">
<id
name="Id"
type="java.lang.Long"
column="id">
<generator class="increment"/>
</id>

<many-to-one class="LineItem" insert="false" update="false" name="lineItem" cascade="delete" >
<column name="orderId"/>
<column name="itemId"/>
</many-to-one>
</class>
------------------------------------------------------


Code between sessionFactory.openSession() and session.close():
Customer customer=(Customer)session.load(Customer.class,customerId);

session.delete(customer);



Full stack trace of any exception that occurs:
13:03:12,861 INFO [STDOUT] Hibernate: delete from lineitem where orderId=? and
itemId=?
13:03:12,908 WARN [JDBCExceptionReporter] SQL Error: 1451, SQLState: 23000
13:03:12,908 ERROR [JDBCExceptionReporter] Cannot delete or update a parent row:
a foreign key constraint fails (`30ss/itemconfiguration`, CONSTRAINT `FK5DF7D0C
3E3D9A5B1` FOREIGN KEY (`orderId`, `itemId`) REFERENCES `lineitem` (`orderId`, `
itemId`))
13:03:12,908 ERROR [AbstractFlushingEventListener] Could not synchronize databas
e state with session


Name and version of the database you are using:
MySQl 5


The generated SQL (show_sql=true):
13:03:12,861 INFO [STDOUT] Hibernate: delete from lineitem where orderId=? and
itemId=?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 9:11 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Just at a cursory glance, what would happen if you add delete-orphan in the cascade directives? e.g. cascade="all, delete-orphan"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 3:18 am 
Newbie

Joined: Thu Feb 16, 2006 8:19 am
Posts: 6
same effect .

I think we are using delete-orphan ,when we delete child from parent collection as explained in the 16 th chapter of Hibernate Reference

jimmy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.