Hi all,
I try to use Hibernate 3.0.5 to map inherited class with the method describled in the document "10.1.5. Table per concrete class". However, Hibernate always creates a table for my parent abstract class. Here is my sampe java code and mapping xml:
[code]
public abstract class Property {
protected long propertyId;
protected String name;
public long getPropertyId() {
return propertyId;
}
public void setPropertyId(long propertyId) {
this.propertyId = propertyId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
abstract Object getPropertyValue();
}
public class StringProperty extends Property {
String value;
Object getPropertyValue() {
return value;
}
}
public class DateProperty extends Property {
Date value;
Object getPropertyValue() {
return value;
}
}
<class name="Property">
<id name="propertyId" column="property_id" unsaved-value="0">
<generator class="increment"/>
</id>
<property name="name" column="name" type="string" />
<union-subclass name="StringProperty" table="string_property">
<property name="value" column="value" type="string" />
</union-subclass>
<union-subclass name="DateProperty" table="date_property">
<property name="value" column="value" type="date" />
</union-subclass>
</class>
[/code]
Hibernate generates the following result:
create table Property (
property_id bigint not null,
name varchar(255),
primary key (property_id)
);
create table date_property (
property_id bigint not null,
name varchar(255),
value date,
primary key (property_id)
);
create table string_property (
property_id bigint not null,
name varchar(255),
value varchar(255),
primary key (property_id)
);
According to the docuemntation, it should have only 2 tables. Has anyone any idea? Thanks in advance!
|