I have many related objects, mostly one-to-many relationships, that are not cascading past a certain level. In the code, I iterate through each child object and create a new Set and populate the Set member with the appropriate child objects, then call update on the root object. I can see that all the child objects are there in the debugger before I call update, but are not persisted to the DB (which is DB2) after I call update. The relationship goes like this:
Root object -> many-to-many -> Child object 1 -> one-to-many -> Child object 2 -> one-to-many -> ...
Here are my mapping files:
Code:
<!-- ROOT LEVEL 0 -->
<hibernate-mapping>
<class name="FooTop" table="foo_top">
<jcs-cache usage="read-write"/>
<id name="fooTopId" column="foo_top_id" type="integer">
<generator class="native"/>
</id>
<set name="fooSets" table="foo_top_foo_set" cascade="all">
<jcs-cache usage="read-write"/>
<key column="foo_top_id"/>
<many-to-many column="foo_set_id" class="FooSet"/>
</set>
<joined-subclass name="joinedClass" table="joined_class">
<key column="joined_class_id"/>
<property name="startDate" column="start_dt" type="date"/>
<property name="endDate" column="end_dt" type="date"/>
</joined-subclass>
</class>
</hibernate-mapping>
<!-- CHILD LEVEL 1 -->
<hibernate-mapping>
<class name="FooSet" table="foo_set">
<jcs-cache usage="read-write"/>
<id name="fooSetId" column="foo_set_id" type="integer">
<generator class="native"/>
</id>
<set name="foos" cascade="all">
<jcs-cache usage="read-write"/>
<key column="foo_set_id"/>
<one-to-many class="Foo"/>
</set>
</class>
</hibernate-mapping>
<!-- CHILD LEVEL 2 -->
<hibernate-mapping>
<class name="Foo" table="foo">
<jcs-cache usage="read-write"/>
<id name="fooId" column="foo_id" type="integer">
<generator class="native"/>
</id>
</class>
</hibernate-mapping>
The
Foo object is not being persisted to the database (as well as all subsequent child sets, which are not shown here). Both FooTop and FooSet appear in the DB after I call
session.update(fooTop). Does this have anything to do with the order in which it persists the objects (breadth-first vrs. depth-first, or anything like that)?
Thanks,
BP