-->
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: Many-to-Many reference delete
PostPosted: Thu Aug 25, 2005 12:17 pm 
Newbie

Joined: Thu Aug 25, 2005 12:00 pm
Posts: 1
I have a Many-to-Many relationship between a Company and Category. In the database I have a bridge table called Company_Category. My delete process for a company works. When I delete a Category I would like to delete all the corresponding rows in the bridge table along with the category.

Hibernate version: 3

Mapping documents:
Company
Code:
<hibernate-mapping package="com.bus.objects">
    <class name="Company" table="Company">
        <id name="companyID" column="Company_ID" type="java.lang.Integer">
            <generator class="native"/>
        </id>

        <property name="companyName" column="Company_Name" type="java.lang.String"  not-null="false" />

        <set name="categories" table="Company_Category" inverse="false" cascade="none" outer-join="true" sort="unsorted">
           <key column="Company_ID" />
           <many-to-many class="Category" column="Category_ID" />
        </set>
     </class>
</hibernate-mapping>

Category
Code:
<hibernate-mapping package="com.bus.objects">
    <class name="Category" table="Category">
        <id name="id" column="Category_ID" type="java.lang.Integer">
            <generator class="native"/>
        </id>

        <property name="categoryName" column="Category_Name" type="java.lang.String"  not-null="false" />
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 12:48 pm 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
Hibernate will do this for you when you remove objects from the collections on the non-inverse side. You can make it work from both sides by making neither side the inverse, but then Hibernate will try to insert objects twice if you add them to the collections of both sides, which you must be aware of.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.