I've been struggling with this problem for about a week now. I've waded through the forum, faq, google search results, etc and found it most helpful for getting started. I'm now working on something more complex and need some further guidance. Below I've listed my Java classes (names changed for work reasons) with the relevant attributes and the corresponding sections of the hibernate mappings:
Class USER - List<CONTAINERA> list
Code:
<class name="USER" table="USER">
<id name="ID" type="string" column="USER_ID"/>
<list name="list" table="USER_CONTAINERA" cascade="all,delete-orphan">
<key column="USER_ID"/>
<list-index column="NODE_ORDER"/>
<one-to-many class="CONTAINERA"/>
</list>
</class>
Class CONTAINERA - List<TASK> tasks, List<CONTAINERB> cbs
Code:
<class name="CONTAINERA" table="CONTAINERA">
<id name="ID" type="string" column="CONTAINERA_ID"/>
<list name="tasks" table="CONTAINERA_TASKS" cascade="all,delete-orphan" lazy="false">
<key column="CONTAINERA_ID"/>
<list-index column="NODE_ORDER"/>
<one-to-many class="TASK"/>
</list>
<list name="cbs" table="CONTAINERA_CONTAINERB" cascade="all,delete-orphan" lazy="false">
<key column="CONTAINERA_ID"/>
<list-index column="NODE_ORDER"/>
<one-to-many class="CONTAINERB"/>
</list>
</class>
Class TASK - List<TASK> subtasks
Code:
<class name="TASK" table="TASK">
<id name="id" type="string" column="TASK_ID"/>
<list name="subtasks" table="TASK_SUBTASKS" cascade="all,delete-orphan" lazy="false">
<key column="TASK_ID"/>
<list-index column="NODE_ORDER"/>
<one-to-many class="TASK" not-found="ignore"/>
</list>
</class>
Class CONTAINERB - ITEMA[] itemas, ITEMB[] itembs
Code:
<class name="CONTAINERB" table="CONTAINERB">
<id name="ID" type="string" column="CONTAINERB_ID"/>
<array name="itemas" table="CONTAINERB_ITEMA" cascade="all,delete-orphan">
<key column="CONTAINERB_ID"/>
<list-index column="NODE_ORDER"/>
<one-to-many class="ITEMA" not-found="ignore"/>
</array>
<array name="itembs" table="CONTAINERB_ITEMB" cascade="all,delete-orphan">
<key column="CONTAINERB_ID"/>
<list-index column="ENTITY_ORDER"/>
<one-to-many class="ITEMB" not-found="ignore"/>
</array>
</class>
The problem is the tables for USER, CONTAINERA, CONTAINERB, ITEMA, and ITEMB are correct only when I specifically call session.saveOrUpdate() with the immediate container. For example, When I add a CONTAINERB object to CONTAINERA, I have to explicitly update CONTAINERA and not the USER who contains CONTAINERA as I would expect. Additionally the TASK table doesn't update even when I add a TASK to CONTAINERA and try to call update on the CONTAINERA.
Any input would be greatly appreciated.