On page 213 of Hibernate In Action is an example of what the we’re trying to do. However it doesn’t talk about actually persisting any changes to the database.
I have debugged my application and have found that an INSERT into CHILD_TABLE is not happening when an INSERT into PARENT_TABLE occurs.
Also, when an PARENT_TABLE UPDATE is done, a database referential integrity error is thrown when a Hibernate remove ParentBeans is executed because it’s not deleting the rows in CHILD_TABLE first.
Here’s the mapping file:
<hibernate-mapping>
<class name="ParentBean" table="PARENT_TABLE" >
<composite-id>
<key-many-to-one name="storeGoalBean" class="StoreGoalBean" column="ID_STR_RT" access="field" />
<key-many-to-one name="employeeBean" class="EmployeeBean" column="ID_EM" access="field" />
</composite-id>
<version name="version" column="VERSION" unsaved-value="negative" type="integer" access="field" />
<property name /> <-- bunch of properties here -->
.
.
.
<list name="changeDates" inverse="true" table="CHILD_TABLE" access="field" cascade="all-delete-orphan">
<key>
<column name="ID_STR_RT" />
<column name="ID_EM" />
</key>
<index column="SEQ_NUM" />
<element type="timestamp" column="CHANGE_DATE" not-null="false" />
</list>
</class>
</hibernate-mapping>
|