Hi,
I'm pretty new to hibernate and i'm not really sure how the cascade works. I did some test on deleting a "Parent" with a collection of "ChildBag" however deletion is not happening in the "ParentBag" and the other records are deleted fine. The weird thing is I didn't get trouble when saving the "Parent" object since all data is saved into all tables.
I did a test to check whether simply deleting the "ChildBag" can propagate the change to the "ParentBag" and it seems like it is working, so I guess I did the wrong mapping in the <bag>
A simple mapping and some information about what i used is below. Any help is appreciated
Hibernate version: 3.2.3.ga
Mapping documents:
Code:
<class name="Parent" table="parent" lazy="false">
<id name="id" column="object_id">
<generator class="native"/>
</id>
<bag name="bags" inverse="true" order-by="bag_id" lazy="false" cascade="all">
<key column="object_id" not-null="true" on-delete="cascade" />
<one-to-many class="ChildBag"/>
</bag>
</class>
<joined-subclass name="Child" table="child_table" extends="Parent">
<key column="object_id"/>
<property name="data" column="from_info"/>
</joined-subclass>
<class name="ParentBag" table="parent_bag" lazy="false">
<id name="bagid" column="bag_id">
<generator class="native" />
</id>
<property name="dateAdded" column="date_added" type="timestamp" />
</class>
<joined-subclass name="ChildBag" table="child_bag" lazy="false" extends="ParentBag">
<key column="bag_id" not-null="true" on-delete="cascade"/>
<property name="priority" />
<property name="object_id" />
</joined-subclass>
Code between sessionFactory.openSession() and session.close():
session.delete(parentObject);
session.getTransaction().commit();
Name and version of the database you are using: MSSQL 2005