My hibernate mappings are:
Extract of the hbm.xml files
Quote:
<hibernate-mapping>
<class name="equicom.offline.transmission_profile.TransmissionHosts" table="TRANSMISSION_HOSTS" dynamic-update="false" dynamic-insert="false">
<id name="hostID" column="HOST_ID" type="integer" unsaved-value="null">
<generator class="native"></generator>
</id>
<hibernate-mapping>
<class name="equicom.offline.transmission_profile.TransmissionCredentials" table="TRANSMISSION_CREDENTIALS" dynamic-update="false" dynamic-insert="false">
<id name="credId" column="CREDENTIAL_ID" type="integer" unsaved-value="null">
<generator class="native"></generator>
</id>
<hibernate-mapping>
<class name="equicom.offline.transmission_profile.TransmissionProfile" table="TRANSMISSION_PROFILE" dynamic-update="false" dynamic-insert="false">
<id name="profileID" column="PROFILE_ID" type="long" unsaved-value="null">
<generator class="native"></generator>
</id>
TransmissionProfile (many map to one) TransmissionCredentials (many map to one) TransmissionHosts
In the EJB layer, saveTransmissionProfile()...
I do a fetch of TransmissionProfile for a particular key. (say object existingTP).
Then create a new instance of TransmissionProfile (newTP = new TransmissionProfile())
set the attributes,
if (existingTP != null)
newTP.profileID = existingTP.profileID
//set the rest of the attributes as received from UI layer
newTP.attrib1 = fromUI.attrib1
...
//and call
newTP.store();
TransmissionProfile.store() contains a
saveOrUpdate(this);