A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Databases
»
Object Relational Mapping
Author
How can I map hibernate component subclasses?
tylor james
Greenhorn
Joined: Nov 23, 2001
Posts: 15
posted
Oct 27, 2004 07:39:00
0
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
Joined: May 17, 2004
Posts: 15
posted
Nov 01, 2004 15:22:00
0
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-value
discriminator-value="C"
Gosh ! Darn it.
I agree. Here's the link:
http://aspose.com/file-tools
subject: How can I map hibernate component subclasses?
Similar Threads
mapping question (hashmap and subclasses)
Hibernate | How to map class with nested component to a stored proc
Hibernate Newbie - 1 to Many Relation Tutorial
mapping a list based on a discriminator
help with hibernate
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter