I have three structures that I have to work with. An AgencyContact, OfficerContact and an Officer.
AgencyContact has a one-to-many relationship with OfficerContact.
OfficerContact has a many to one relationship with Officer.
AgencyContact.hbm.xml part for officercontact is
Code:
<bag name="officerContacts" lazy="false" cascade="all-delete-orphan" inverse="true">
<key column="AGENCY_CONTACT_ID"/>
<one-to-many class="OfficerContact"/>
</bag>
OfficerContact.hbm.xml
Code:
<many-to-one name="officer"
class="Officer"
column="OFFICER_ID"
cascade="none"
lazy="false" />
Here's the very weird part. When I delete an agencyContact, it tries to delete an Officer. This fails because other objects are referencing that Officer.
So, am I just not understanding what cascade="none" is? I thought it was basically me telling Hibernate "worry about the relationships (fill in the FK when necessary), but don't actually try to insert/update/delete when it comes to the Officer".
As for the code, the issue might be that I'm first getting the AgencyContact and then (using Spring's hibernateTemplate class) passing that object into a generic delete method. But I'm not exactly sure why that would cause a problem. The getting and the deleting of the object are in the same hibernate session.