Hi there. Let's suppose there is a top level entiry object called ClaimCase. In each claim case you can have 0+ instances of Party. Party can be subclassed, examples are Claimant, Employer and EmployerClaimant.
Also, each ClaimCase can have 0+ instance of Requirement and each instance of Requirement can be 0+ instance of Activity.
The hibernate mapping would look something like this:
Code:
<?xml version="1.0"?>
<!-- Created with Liquid XML Studio - FREE Community Edition 7.1.4.1284 (http://www.liquid-technologies.com) -->
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"[]>
<hibernate-mapping package="com.standard.ulterap8.claimintake.dao.impl">
<class name="Party" abstract="true" table="PARTY" optimistic-lock="version" polymorphism="implicit">
<meta attribute="implements">com.xxx.xxx.xxx.xxx.Auditable</meta>
<id name="partyId" type="integer">
<meta attribute="scope_set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<column name="PARTY_ID" not-null="true">
</column>
<generator class="sequence">
</generator>
</id>
<discriminator column="PARTY_TYPE" type="string" />
<version name="version" type="integer" access="field" column="OBJ_VERSION" unsaved-value="negative" />
<property name="createdTimestamp" column="CREATE_TIMESTAMP" type="com.ipd.common.dao.HibernateUTC$TimestampType" not-null="true">
<meta attribute="use-in-equals">true</meta>
</property>
<!-- Deleted Properties --->
<subclass name="Caller" discriminator-value="Caller">
<!-- Deleted Properties --->
</subclass>
</class>
<subclass abstract="true" name="PartyProfile" extends="Party">
<!-- Deleted Properties --->
<many-to-one name="claimCase" class="ClaimCase" column="CASE_ID" foreign-key="PRTY_CLMCASE_FK" />
<subclass name="Claimant" discriminator-value="Claimant">
<!-- deleted properties --->
</subclass>
<subclass name="Employer" discriminator-value="Employer">
<!-- deleted properties --->
</subclass>
<subclass name="EmployerClaimant" discriminator-value="EmployerClaimant">
<!-- deleted properties --->
</subclass>
</subclass>
<class name="Requirement" table="REQUIREMENT" optimistic-lock="version">
<meta attribute="implements">com.xxx.xxx.xxx.xxx.Auditable</meta>
<id name="requirementID" type="integer">
<meta attribute="scope_set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<column name="REQ_ID" not-null="true">
</column>
<generator class="sequence">
</generator>
</id>
<version name="version" type="integer" access="field" column="OBJ_VERSION" unsaved-value="negative" />
<property name="configID" type="integer" column="REQ_CFG_ID" not-null="true">
<meta attribute="use-in-equals">true</meta>
</property>
<property name="name" type="string" length="200" column="REQ_NM" not-null="true" />
<!-- deleted properties --->
<property name="createdTimestamp" column="CREATE_TIMESTAMP" type="com.ipd.common.dao.HibernateUTC$TimestampType" not-null="true">
<meta attribute="use-in-equals">true</meta>
</property>
<many-to-one name="claimCase" class="ClaimCase" column="CASE_ID" not-null="true" foreign-key="REQUIREMENT_CLMCASE_FK" />
<set name="activities" inverse="true" cascade="all, delete-orphan" lazy="false" order-by="SORT_KEY asc">
<key column="REQ_ID" />
<one-to-many class="Activity" />
</set>
</class>
<class name="Activity" table="ACTIVITY" optimistic-lock="version">
<meta attribute="implements">com.xxx.xxx.xxx.xxx.Auditable</meta>
<id name="activityID" type="integer">
<meta attribute="scope_set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<column name="ACTIVITY_ID" not-null="true">
</column>
<generator class="sequence">
</generator>
</id>
<version name="version" type="integer" access="field" column="OBJ_VERSION" unsaved-value="negative" />
<property name="createdTimestamp" column="CREATE_TIMESTAMP" type="com.ipd.common.dao.HibernateUTC$TimestampType" not-null="true">
<meta attribute="use-in-equals">true</meta>
</property>
<property name="dependencyReqID" type="integer" column="DEP_REQ_ID" not-null="true" />
<property name="configID" type="integer" column="ACT_CFG_ID" not-null="true">
<meta attribute="use-in-equals">true</meta>
</property>
<!-- deleted properties --->
<many-to-one name="requirement" class="Requirement" column="REQ_ID" not-null="true" foreign-key="ACTIVITY_REQ_FK" />
</class>
<class name="ClaimCase" table="CLAIMCASE" optimistic-lock="version">
<meta attribute="implements">com.xxx.xxx.xxx.xxx.Auditable</meta>
<meta attribute="implement-equals">true</meta>
<meta attribute="generated-class">com.xxx.xxx.xxx.xxx.xxx.ClaimCaseBase</meta>
<meta attribute="scope-field">protected</meta>
<id name="ciwId" type="integer">
<meta attribute="scope_set">protected</meta>
<meta attribute="use-in-tostring">true</meta>
<column name="CASE_ID" not-null="true">
</column>
<generator class="sequence" />
</id>
<version name="version" access="field" column="OBJ_VERSION" type="integer">
</version>
<property name="createdTimestamp" type="com.ipd.common.dao.HibernateUTC$TimestampType" column="CREATE_TIMESTAMP" not-null="true">
<meta attribute="use-in-equals">true</meta>
</property>
<!-- deleted properties --->
<property name="sectorCode" type="string" length="7" column="SECTOR_CD" not-null="false" />
<one-to-one name="insuredInfo" class="InsuredInfo" property-ref="claimCase" cascade="all" />
<set name="intakeActivities" inverse="true" cascade="all, delete-orphan" lazy="false" order-by="CREATE_TIMESTAMP asc">
<key column="CASE_ID" />
<one-to-many class="IntakeActivity" />
</set>
<set name="parties" inverse="true" cascade="all, delete-orphan" lazy="false">
<meta attribute="scope_set">protected</meta>
<key column="CASE_ID" />
<one-to-many class="PartyProfile" />
</set>
<set name="requirements" inverse="true" cascade="all, delete-orphan" lazy="false" order-by="SORT_KEY">
<key column="CASE_ID" />
<one-to-many class="Requirement" />
</set>
<property name="lastChangeDate" type="com.ipd.common.dao.HibernateUTC$TimestampType" column="LAST_CHG_DATE" not-null="false" />
<property name="lastChangeUser" type="string" length="100" column="LAST_CHG_USER" not-null="false" />
</class>
</hibernate-mapping>
I've noticed that when we save by using session.persist(), even if I changed only one thing in ClaimCase (topmost object) or in Activity (bottomost object), the entire object gets updated. (Meaning that the ClaimCase, Employer, Claimant, EmployerClaimant, Requirement and Activities for the claim case are updated ... because when I look at the database, I discovered all the version numbers are changed. Wondering if anyone else experience the same thing and is there a way to tell Hibernate to "smart" update?