-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Inheritance and one-to-one association mapping
PostPosted: Wed Nov 05, 2008 4:27 pm 
Newbie

Joined: Wed Nov 05, 2008 4:10 pm
Posts: 1
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.

_________________
Henry


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.