-->
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: CONDITIONAL MANY-TO-MANY CASCADE
PostPosted: Thu Nov 25, 2004 11:25 am 
Beginner
Beginner

Joined: Fri Nov 19, 2004 6:41 am
Posts: 39
Location: Stockholm, Sweden
Hibernate version:

2.1.6

Mapping documents:

Order.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
   package="se.andreaseriksson.hibernate.many">

   <class name="Order" table="Orders" proxy="Order">
      <id name="id">
         <generator class="uuid.hex"/>
      </id>
      <property name="comment" column="comment"/>
      
      <many-to-one name="customer" column="customer_id" cascade="save-update"/>
      
      <many-to-one name="purchaseDetail" column="purchase_detail_id" cascade="all"/>
      
      <set name="products" table="OrderLines" inverse="false" cascade="all" lazy="false">
          <key column="order_id"/>
          <many-to-many column="product_id" class="se.andreaseriksson.hibernate.many.Product"/>
      </set>
   </class>
   
</hibernate-mapping>


Order.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
   package="se.andreaseriksson.hibernate.many">

   <class name="Product" table="Products" proxy="Product">
      <id name="id">
         <generator class="uuid.hex"/>
      </id>
      <property name="comment" column="comment"/>
      
      <set name="orders" table="OrderLines" inverse="true" cascade="save-update" lazy="false">
          <key column="product_id"/>
          <many-to-many column="order_id" class="se.andreaseriksson.hibernate.many.Order"/>
      </set>
   </class>
   
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Not needed

Full stack trace of any exception that occurs:

Name and version of the database you are using:

McKoi 1.0.3

The generated SQL (show_sql=true):



Debug level Hibernate log excerpt:

Dunno

Question:

I'm trying to accomplish a conditional cascade on delete without any success.
With the above mapping files in mind, let me narrow it down to just one many-to-many scenario (compare with the Order - Product in above mapping).

[TABLE A] many-to-many [TABLE B]

A sample relationship:

Row A1 in table A connected to row B1 in table B through intermediate row AB1 in table AB.

Row A2 in table A connected to row B1 in table B through intermediate row AB2 in table AB.

If a delete occurs on A1, I'd like AB1 to be deleted but NOT B1 cause it's connected to A2.

BUT(!)

Another sample relationship:e

Row A1 in table A connected to row B1 in table B through intermediate row AB1 in table AB.

If a delete occurs on A1, I'd like AB1 to be deleted AND B1 cause B1 doesn't have another parent.

Is this possible, and if so -> HOW?

PS. I've tried the Lifecycle approach without success...

Regards, Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 12:48 pm 
Regular
Regular

Joined: Fri Nov 12, 2004 12:07 am
Posts: 57
Location: Beijing,China
Hi andreas_swe:

In fact,it looks that your two cases can be looked as one case that the B row should be deleted when it is orphan.I'm sorry for i have to go to bed now and have no time trying your issue.

Have you tried cascade="all-delete-orphan"?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 1:29 pm 
Beginner
Beginner

Joined: Fri Nov 19, 2004 6:41 am
Posts: 39
Location: Stockholm, Sweden
amjn wrote:
Hi andreas_swe:

In fact,it looks that your two cases can be looked as one case that the B row should be deleted when it is orphan.I'm sorry for i have to go to bed now and have no time trying your issue.

Have you tried cascade="all-delete-orphan"?


Thanks for the tip!

But to bad it's not working.

I get a foreign key violation when the row in B is going to be deleted, cause table AB cannot have null values... which is correct.

Need more tips, please!

Regards, Andreas


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.