Hello!
I have 3-level class hierarchy:
Code:
class RootClass {
Integer id;
}
class Product extends RootClass {
Double price;
}
class SubProduct extends Product {
String color;
}
RootClass is mapped to "root" table:
Code:
<class name="RootClass" table="root">
<id unsaved-value="null" type="int" name="id">
....
</id>
<discriminator column="classType"/>
...
</class>
Product class is mapped to products table via join:
Code:
<subclass name="Product" extends="RootClass">
<join table="products">
<key column="id"/>
<property name="price" not-null="true"/>
</join>
</subclass>
I want to map SubProduct class to same table as Product class. How can I do such mapping?
Variant 1:
Code:
<subclass name="SubProduct" extends="Product">
<join table="products">
<key column="id"/>
<property name="color"/>
</join>
</subclass>
This mapping don't work - when I call save(), Hibernate tries to insert row to "products" table twice (first row for Product mapping and second row for SubProduct mapping.)
Variant 2:
Code:
<subclass name="SubProduct " extends="Product">
<property name="color"/>
</subclass>
In this case, Hibernate creates "color" column in a root class table ("root"). "products" table is not used at all.
Any suggestions?