I'm trying to determine the best way to avoid needless SQL updates being issued by Hibernate for collections when I update a detached parent object in a new session. I'm using Hiberate 3.1. Each time the parent object is updated, only one of the elements in the collection needs updating. The rest of the elements are unchanged. The parent/child association is not currently defined as bi-directional. That might be the easy answer to our problems, not sure, but I'd like to know if there are any other options besides making the association bi-directional. My mappings are below. The assoications involved are the crewMembers and passengers collections.
Grant
Code:
<hibernate-mapping package="gov.seahawk.model">
<!-- Hibernate class mapping -->
<union-subclass
name="VesselArrival"
entity-name="gov.seahawk.model.VesselArrivalNoticeEntity"
extends="gov.seahawk.model.ArrivalNoticeEntity"
table="VESSEL_NOA" dynamic-insert="true" dynamic-update="true" >
<property name="facilityName" type="string" column="VESSEL_FACILITY_NAME" length="100" />
<property name="berth" type="string" column="VESSEL_BERTH" length="100" />
<many-to-one
class="Vessel"
name="vessel"
column="VESSEL_ID"
foreign-key="VESSEL_NOA_VESSEL_ID_FK"
lazy="false"
cascade="none"/>
<many-to-one
class="Facility"
name="facility"
column="FACILITY_ID"
foreign-key="VESSEL_NOA_FACILITY_ID_FK"
lazy="false"/>
<many-to-one
class="DataSource"
name="dataSource"
column="DATA_SOURCE_ID"
foreign-key="VESSEL_NOA_DATA_SOURCE_ID_FK"
lazy="false"/>
<set name="cargo" table="VESSEL_NOA_CONVEYANCE" cascade="all">
<key column="VESSEL_NOA_ID" foreign-key="VESSEL_NOA_CONVEYANCE_VESSEL_NOA_ID_FK"/>
<many-to-many class="Conveyance" column="CONVEYANCE_ID" foreign-key="VESSEL_NOA_CONVEYANCE_CONVEYANCE_ID_FK"/>
</set>
<set name="passengers" cascade="all">
<key column="VESSEL_NOA_ID" foreign-key="PASSENGER_VESSEL_NOA_ID_FK"/>
<one-to-many class="Passenger"/>
</set>
<set name="crewMembers" cascade="all">
<key column="VESSEL_NOA_ID" foreign-key="CREW_MEMBER_VESSEL_NOA_ID_FK"/>
<one-to-many class="CrewMember"/>
</set>
<set name="certificates" table="VESSEL_NOA_CERTIFICATES" cascade="all">
<key column="VESSEL_NOA_ID"
foreign-key="VESSEL_NOA_CERTIFICATES_VESSEL_NOA_ID_FK"/>
<many-to-many
class="VesselCertificate"
column="VESSEL_CERTIFICATE_ID"
foreign-key="VESSEL_NOA_CERTIFICATES_VESSEL_CERTIFICATE_ID_FK"/>
</set>
<set name="equipmentInfo" table="VESSEL_NOA_EQUIPMENT_INFO" cascade="all">
<key column="VESSEL_NOA_ID"
foreign-key="VESSEL_NOA_EQUIPMENT_INFO_VESSEL_NOA_ID_FK"/>
<many-to-many
class="VesselEquipment"
column="VESSEL_EQUIPMENT_ID"
foreign-key="VESSEL_NOA_EQUIPMENT_INFO_VESSEL_EQUIPMENT_ID_FK"/>
</set>
<set name="securityInfo" table="VESSEL_NOA_SECURITY_INFO" cascade="all">
<key column="VESSEL_NOA_ID"
foreign-key="VESSEL_NOA_SECURITY_INFO_VESSEL_NOA_ID_FK"/>
<many-to-many
class="VesselSecurity"
column="VESSEL_SECURITY_ID"
foreign-key="VESSEL_NOA_SECURITY_INFO_VESSEL_SECURITY_ID_FK"/>
</set>
<list name="previousPorts" table="VESSEL_NOA_PREVIOUS_PORTS" cascade="all">
<key column="VESSEL_NOA_ID"
foreign-key="VESSEL_NOA_PREVIOUS_PORTS_VESSEL_NOA_ID_FK"/>
<list-index column="PREVIOUS_PORT_INDEX"/>
<many-to-many
class="VesselPreviousPort"
column="VESSEL_PREVIOUS_PORT_ID"
foreign-key="VESSEL_NOA_PREVIOUS_PORTS_VESSEL_PREVIOUS_PORT_ID_FK"/>
</list>
</union-subclass>
</hibernate-mapping>
<hibernate-mapping package="gov.seahawk.model">
<class name="CrewMember" table="CREW_MEMBER">
<id name="key" column="ID" type="string">
<generator class="guid"/>
</id>
<property name="position" column="POSITION" type="string"/>
<property name="embarkDate" type="java.util.Date" column="EMBARK_DATE"/>
<property name="debarkDate" type="java.util.Date" column="DEBARK_DATE"/>
<component class="Location" name="embarkLocation">
<property name="name" column="EMBARK_LOCATION_NAME" length="100"/>
</component>
<component class="Location" name="debarkLocation">
<property name="name" column="DEBARK_LOCATION_NAME" length="100"/>
</component>
<many-to-one name="person"
class="Person"
column="PERSON_ID"
foreign-key="CREW_MEMBER_PERSON_ID_FK"
cascade="none"/>
</class>
</hibernate-mapping>
<hibernate-mapping package="gov.seahawk.model">
<class name="Passenger" table="PASSENGER">
<id name="key" column="ID" type="string">
<generator class="guid"/>
</id>
<property name="embarkDate" type="java.util.Date" column="EMBARK_DATE"/>
<property name="debarkDate" type="java.util.Date" column="DEBARK_DATE"/>
<component class="Location" name="embarkLocation">
<property name="name" column="EMBARK_LOCATION_NAME"/>
</component>
<component class="Location" name="debarkLocation">
<property name="name" column="DEBARK_LOCATION_NAME"/>
</component>
<many-to-one name="person"
class="Person"
column="PERSON_ID"
foreign-key="PASSENGER_PERSON_ID_FK"
cascade="none"/>
</class>
</hibernate-mapping>