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.  [ 2 posts ] 
Author Message
 Post subject: Delete Parent and Child Records
PostPosted: Thu Dec 15, 2005 6:04 pm 
Newbie

Joined: Thu Dec 15, 2005 5:57 pm
Posts: 1
Hi Everyone,

I have two tables with parent and child relationships.
I need to delete two records from both tables at one shot.

I created a collection in which i have parent object and this parent object again contain child object
And I passed this collection to deleteAll method.

Hibernatetemple().deleteAll(collection)

I have my mapping file like this
Parent hbm file:

<bag name="mmIdSet" lazy="true" inverse="true" cascade="all, delete-orphan">
<key column="EmpId"></key>
<one-to-many class="ChildClass"/>
</bag>

Child hbm file :

<many-to-one name="employee" class="ParentClass" cascade="all"
outer-join="auto" update="true" insert="true" column="EmpId" />

But when i try to delete..Im getting SQLException saying
Integrity Constraint Violated: child record found
And I can see the sql query like this
delete from parenttable where empid =?

It is trying to delete parent record first. Is there anyway to configure so that hibernate can delete child record first and then parent record

Please help me regarding this issue.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 3:14 pm 
Newbie

Joined: Mon Dec 12, 2005 11:37 am
Posts: 14
Well the effect that you are getting is because in you <bag> you have inverse=true, making the parent as the inverse end of the join i.e

From your example, I think you dont actually mean to have the inverse anyway. So removing that would be the simplest thing.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.