I have have all kinds of entities in my application which have addresses so i have a separate address table that they all have foreign keys to.
The address mapping is as follows:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true">
<class name="Address" table="ADDRESS" >
<id name="id" column="ID" type="int" unsaved-value="-1" access="field">
<generator class="identity"/>
</id>
<property name="line1" column="LINE1" not-null="true"/>
<property name="line2" column="LINE2"/>
<property name="city" column="CITY" not-null="true"/>
<property name="state" column="STATE" not-null="true"/>
<property name="postalCode" column="POSTAL_CODE" not-null="true"/>
</class>
</hibernate-mapping
For instance a person has a work address.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true">
<class name="GenericPerson" table="GENERIC_PERSON" >
<id name="id" column="ID" type="int" unsaved-value="-1" access="field">
<generator class="identity"/>
</id>
<property name="firstName" column="FIRST_NAME"/>
<property name="lastName" column="LAST_NAME"/>
<many-to-one name="workAddress" class="com.mbs.model.domainobjects.entities.Address"
column="WORK_ADDRESS_ID" cascade="all"/>
</class>
</hibernate-mapping>
If i set the workAddress property to null the foreign key to the address table "WORK_ADDRESS_ID" is made null when the session is committed. But the address is not deleted. I would like the address to be deleted when the property is set to null. This seems like a fairly common requirement, so I assume there is an easy way to do this that I must have overlooked.
Thanks for your help.