• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I map hibernate component subclasses?

 
tylor james
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I map eg.Name subclasses? for example:

public ShortName extends Name
{
private String shortName;
...
}


<class name="eg.Person" table="person">
<id name="Key" column="pid" type="string">
<generator class="uuid.hex"/>
</id>
<property name="birthday" type="date"/>
<component name="Name" class="eg.Name"> <!-- class attribute optional -->
<property name="initial"/>
<property name="first"/>
<property name="last"/>
</component>
</class>
 
Praveen Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use something called as a discriminator column

Below is an edited mapping ...

<hibernate-mapping>
<class
name="b2b.common.hibernate.Contact"
table="CONTACT"
dynamic-update="true"
dynamic-insert="false"
discriminator-value="C"
>

<id
name="id"
column="ID"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="native">
</generator>
</id>

<discriminator
column="CLASS_TYPE"
type="string"
/>

<property
name="firstName"
>
<column
name="FIRST_NAME"
length="16"
not-null="true"
/>
</property>

<property
name="lastName"
type="java.lang.String"
update="true"
insert="true"
access="property"
>
<column
name="LAST_NAME"
length="20"
not-null="true"
/>
</property>

<subclass
name="b2b.common.hibernate.BusinessEntityContact"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="B"
>

<subclass
name="b2b.common.hibernate.BuyerGroupContact"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="G"
>
<property
name="buyerID"
type="java.lang.String"
update="true"
insert="true"
access="property"
>
<column
name="BUYER_ID"
/>
</property>

</subclass>
</class>

</hibernate-mapping>discriminator-valuediscriminator-value="C"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic