-->
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: Join Table cascade delete
PostPosted: Thu Feb 05, 2009 6:58 pm 
Newbie

Joined: Mon Jan 26, 2009 12:14 pm
Posts: 8
OK, I have setup a scenaior previously where if I remove the relationship of a parent it will delete that child. That was a choir but with your good help I got it.

Now I have a more difficult situation. I have parent child relationship, however it was modeled as such. The database was modeled for many to many with join table. So I have a parent, child and parentchild table.

The join table parentchild has its own unique key as its primary key and then the two Foreign keys from parent and child. The save works fine but the delete I am having issues with. When I remove the relationship(i.e. remove from list) then I want it to delete parentchild row first then the child. The following is how it is mapped.

PARENT

<!-- bi-directional one-to-many association to ParentChild-->
<set name="ParentChild" lazy="false" inverse="true" cascade="all">
<key>
<column name="PARENT_ID" />
</key>
<one-to-many class="ParentChild" />
</set>

PARENT CHILD RELATIONSHIP

<class name="PARENT_CHILD" table="T_PARENT_CHILD" dynamic-update="true" lazy="false">

<id name="parentchildID" type="java.lang.Long" column="PARENT_CHILD_ID">
<generator class="sequence">
<param name="sequence">seq_001</param>
</generator>
</id>

<!-- Associations -->

<!-- bi-directional many-to-one association to Parent -->
<many-to-one name="parent" class="Parent" cascade="all" not-null="true" lazy="false">
<column name="PARENT_ID" />
</many-to-one>

<!-- bi-directional many-to-one association to Child-->
<many-to-one name="child" class="Child" not-null="true" cascade="all" lazy="false">
<column name="CHILD_ID" />
</many-to-one>

</class>
CHILD
<set name="ParentChilds" lazy="false" inverse="true" cascade="none" >
<key column="CHILD_ID" foreign-key="CHILD_ID"></key>
<one-to-many class="ParentChild" />
</set>


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.