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>
IndividualCode:
<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>