-->
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: Problem with foreign-key / cascade delete with many-to-many
PostPosted: Mon Apr 07, 2008 6:06 am 
Newbie

Joined: Thu Mar 13, 2008 12:59 pm
Posts: 2
Hibernate version: 3.2.6.ga

Hi,

I have two classes with an unidirectional many-to-many relation, the relation is stored in a separate table:

Code:
<hibernate-mapping>
  <class name="Org" table="ORG">
    <id name="id" type="long">
      <column name="ID" />
      <generator class="native" />
    </id>
    <property name="orgkey" type="string">
      <column name="ORGKEY" length="20" />
    </property>
    <property name="name" type="string">
      <column name="NAME" length="50" />
    </property>

    <set name="pakete" table="ORGPAKET" >
      <key foreign-key="FKOrgPaketOrg" on-delete="cascade">
        <column name="ORGID" scale="0" index="IDXOrgPaketOrg" />
      </key>

      <many-to-many foreign-key="FKOrgPaketPaket" class="Paket">
        <column name="PAKETID" scale="0" index="IDXOrgPaketPaket" />
      </many-to-many>
    </set>
  </class>
</hibernate-mapping>


the generated oracle ddl for the relations table's fk constraints :
Code:
alter table HIBERNATE.ORGPAKET
add constraint FKOrgPaketOrg
foreign key (ORGID)
references HIBERNATE.ORG
on delete cascade;

alter table HIBERNATE.ORGPAKET
add constraint FKOrgPaketPaket
foreign key (PAKETID)
references HIBERNATE.PAKET;


the first constraint contains 'on delete cascade'. When a record in the first table is deleted, all relations are deleted. I also need a 'on delete cascade' in the second constraint, but I did not find a way to define one?
Does anybody have a solution for this?

thanks,
Bernd


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.