hibernate mapping of subclass and individual fields
I have this class hierachy:
class A
{
private String a1;
private Class B a2;
// getter & setter
}
class B
{
private String b1;
private String b2;
// getter & setter
}
class C extends class A
{
private String c1;
// getter and setter for c1;
}
And I need to map C to a single table in a databas开发者_StackOverflowe using hibernate. I try this:
<class name="com.C"
table="myTable" catalog="myCatalog"
polymorphism="implicit">
<property name="a1" type="string">
<column name="column1" length="40" not-null="true" />
</property>
<property name="a2" type="????">
?? B should map to column2 and column3
</property>
<property name="c1" type="string">
<column name="column4" length="40" not-null="true" />
</property>
</class>
How to map field b of class B?
Thanks,
Hi found it using component tag:
<class name="com.C"
table="myTable" catalog="myCatalog"
polymorphism="implicit">
<property name="a1" type="string">
<column name="column1" length="40" not-null="true" />
</property>
<component name="a2" class="com.B">
<property name="b1" type="java.lang.Integer">
<column name="column2" />
</property>
<property name="b2" type="java.lang.Integer">
<column name="column3" />
</property>
</component>
<property name="c1" type="string">
<column name="column4" length="40" not-null="true" />
</property>
</class>
精彩评论