-->
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: Overriding a property based on sublcass instance
PostPosted: Fri Mar 18, 2005 1:42 pm 
Regular
Regular

Joined: Fri Feb 13, 2004 10:02 pm
Posts: 90
Hibernate version:
3.0rc1

I have 3 tables; Entity, Business, and Individual. Individual extends Entity. and Business extends Entity. If the object is an instance of an Individual, I need to initialize the taxID to an SSN Object, or to a FederalIdNumber if it is a Business. Below are my mappings. I initially thought I could just do a "join" tag in the mappings for Business and Individual, and then simply map the component within the join tag. However, you cannot specify a join within a joined-subclass. Does anyone have any other ideas for a mapping strategy?

Entity
Code:
<hibernate-mapping package="com.llic.business">
  <class name="Entity" table="Entity">
   
   <meta attribute="implements">LaserBusiness</meta>
   
    <id name="id" column="entityid" type="java.lang.Long">
      <meta attribute="scope-set">private</meta>
     
      <generator class="native" />
     
    </id>
   
   
   <!-- Needs to be a FederalIdNumber is a Business, an SSN if an Individual -->
    <component name="taxId" class="com.llic.business.FederalIdNumber" >
       <property name="number" column="fedIdNumber" type="string" />
    </component>
   
    <property name="name" column="name" type="string" not-null="true" />
   
  </class>
</hibernate-mapping>



Individual
Code:
<hibernate-mapping package="com.llic.business">
 
  <joined-subclass name="Individual" extends="Entity" table="Individual" >
   
    <key column="EntityId"/>
   
    <property name="firstName" column="firstName" type="string" length="254"/>
       
    <property name="middleName" column="middleName" type="string" length="20"/>
   
    <property name="personalTitle" column="personalTitle" type="string" length="10"/>
   
    <property name="suffix" column="suffix" type="string" length="20"/>
   
    <property name="nickName" column="nickName" type="string" length="20"/>
     
     <!-- TODO birthState, MaritalStatus -->
     
    <property name="issueAge" column="issueAge" type="java.lang.Integer"/>
   
    <property name="gender" column="gender" type="java.lang.Character"/>
   
    <property name="birthDate" column="birthDate" type="java.util.Date" />
   
   <!-- todo Employer
   <many-to-one name="employer" class="Business" column="employerId"  cascade="all,delete-orphan">
      <column name="employerId"/></column>
   </many-to-one>
   
   -->
  </joined-subclass>
 
</hibernate-mapping>



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.