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