I’m using hibernate to store two types of User objects. The first one is the generic UserData, and the second one is a ReviewerData (Subclass of UserData with additional attributes).
The hibernate mapping is defined below. I can create both objects regardless whether it’s a UserData or ReviewerData without any problem. However I cannot convert a generic UserData to become ReviewerData. The scenario is that, today a user may be registered as a normal user (e.g UserData), tomorrow, this user may become a reviewer (ReviewerData). Can anyone help me save an existing UserData as a ReviewerData using the following hibernate mapping?
Kind regards,
Roy
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.passtheboard.user.model.UserData" table="USER" lazy="false">
<id name="id" column="id" type="string" length="20"/>
<property name="password" type="string" length="20" not-null="true"/>
<property name="firstName" type="string" length="30" not-null="true"/>
<property name="middleName" type="string" length="30"/>
<property name="lastName" type="string" length="30" not-null="true"/>
<property name="birthDate" type="date"/>
<property name="gender" type="string" length="1" not-null="true"/>
<component
name="homeAddress"
class="com.baligya.util.model.AddressTransferObject">
<property name="street" column="homeStreet" type="string" length="100" not-null="true"/>
<property name="city" column="homeCity" type="string" length="30" not-null="true"/>
<property name="state" column="homeState" type="string" length="30"/>
<property name="zipCode" column="homeZip" type="string" length="10"/>
<property name="country" column="homeCountry" type="string" length="2" not-null="true"/>
</component>
<component
name="workAddress"
class="com.baligya.util.model.AddressTransferObject">
<property name="street" column="workStreet" type="string" length="100" not-null="true"/>
<property name="city" column="workCity" type="string" length="30" not-null="true"/>
<property name="state" column="workState" type="string" length="30"/>
<property name="zipCode" column="workZip" type="string" length="10"/>
<property name="country" column="workCountry" type="string" length="2" not-null="true"/>
</component>
<component name="homePhone"
class="com.baligya.util.model.TelephoneTransferObject">
<property name="countryCode" column="homePhoneCountry" type="string" length="3"/>
<property name="areaCode" column="homePhoneArea" type="string" length="5"/>
<property name="number" column="homePhoneNumber" type="string" length="8"/>
</component>
<component name="workPhone"
class="com.baligya.util.model.TelephoneTransferObject">
<property name="countryCode" type="string" column="workPhoneCountry" length="3"/>
<property name="areaCode" type="string" column="workPhoneArea" length="5"/>
<property name="number" type="string" column="workPhoneNumber" length="8"/>
</component>
<component name="cellPhone"
class="com.baligya.util.model.TelephoneTransferObject">
<property name="countryCode" type="string" column="cellPhoneCountry" length="3"/>
<property name="areaCode" type="string" column="cellPhoneArea" length="5"/>
<property name="number" type="string" column="cellPhoneNumber" length="8"/>
</component>
<property name="email" type="string" length="50"/>
<component name="auditData"
class="com.baligya.util.model.AuditData">
<property name="updateCount" type="int"/>
<property name="updateDateTime" type="timestamp"/>
<property name="updatedBy" type="string" length="20"/>
</component>
<list
name="roles"
table="userRoles"
lazy="false" cascade="all,delete-orphan" fetch="join">
<!--
<key column="id" not-null="true"/>
-->
<key not-null="true">
<column name="id" unique-key="roleKey"/>
</key>
<list-index column="roleIndex"/>
<composite-element class="com.passtheboard.user.model.UserRole">
<property name="name" length="20" unique-key="roleKey"/>
</composite-element>
</list>
<joined-subclass name="com.passtheboard.reviewer.model.ReviewerData" table="REVIEWER" >
<key column="id"/>
<property name="degreeID" type="string" length="20"/>
<property name="courseID" type="string" length="20"/>
<property name="accountStatus" type="string" length="20"/>
<component name="college"
class="com.passtheboard.reviewer.model.CollegeData">
<property name="collegeName" column="college" type="string" length="60"/>
<component
name="address"
class="com.baligya.util.model.AddressTransferObject">
<property name="street" column="collegeStreet" type="string" length="100" not-null="true"/>
<property name="city" column="collegeCity" type="string" length="30" not-null="true"/>
<property name="state" column="collegeState" type="string" length="30"/>
<property name="zipCode" column="collegeZip" type="string" length="10"/>
<property name="country" column="collegeCountry" type="string" length="2" not-null="true"/>
</component>
<property name="yearStarted" column="collegeYearStarted" type="int"/>
<property name="yearGraduated" column="collegeYearGrad" type="int"/>
</component>
<property name="planCode" type="string" length="10"/>
<property name="targetExamDate" column="examDate" type="date"/>
</joined-subclass>
</class>
</hibernate-mapping>