Hi,
I have the following mapping :
Code:
<hibernate-mapping>
<class name="Establishment" table="establishment">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="lastUpdateDate"/>
<many-to-one name="address"
column="addressId"
class="Address"
lazy="false"
unique="true"
cascade="all"/>
<component name="contactInformation" class="ContactInformation">
<property name="telephone"/>
<property name="fax"/>
<property name="tollFree"/>
<property name="email"/>
<property name="website"/>
</component>
</class>
</hibernate-mapping>
and
Code:
<hibernate-mapping>
<class name="Address" table="address">
<id name="id" column="id">
<generator class="native"/>
</id>
<many-to-one name="country"
column="countryId"
class="Country"
lazy="false"
not-null="true"/>
<many-to-one name="city"
column="cityId"
class="City"
lazy="false"/>
<joined-subclass name="CanadianAddress" table="address_ca">
<key column="addressId"/>
<property name="number"/>
<property name="street"/>
<many-to-one name="province"
column="provinceId"
class="Province"
lazy="false"
unique="true"
not-null="true"/>
<property name="postalCode"/>
</joined-subclass>
<joined-subclass name="AmericanAddress" table="address_us">
<key column="addressId"/>
<property name="number"/>
<property name="street"/>
<many-to-one name="state"
column="stateId"
class="State"
lazy="false"
unique="true"
not-null="true"/>
<property name="zipCode"/>
</joined-subclass>
<joined-subclass name="InternationalAddress" table="address_intl">
<key column="addressId"/>
<property name="address"/>
</joined-subclass>
</class>
</hibernate-mapping>
The idea is having a one-to-one relationship between Establishment and Address, in which has 3 subclasses. When I try to change the address of an establishment (changing from CanadianAddress to AmericanAddress), a new entry in the DB gets created and the old one remains. I've tried to put cascade="all-delete-orphan", but I get an Exception ("single-valued associations do not support orphan delete").
How should setup the mapping to achieve the "delete-orphan", other than deleting them manually?
Thanks in advance.