继承映射就是有一个基类和几个继承类共用一表作为映射。配置写在一个hbm.xml文件中。
配置方法:
1. 基类的<class name="xxx"处加上
discriminator-value="xxxx">
2. 在基类的配置内,加上
<discriminator column="xxxx"></discriminator> 分别类型不同的字段名
3. 加上<subclass name="Company" discriminator-value="xxxx">来表示子类的区分
<hibernate-mapping package="com.wolfgang.domain" > <class name="Party" table="t_party" discriminator-value="X"> <id name="id" type="integer" column="id"> <generator class="increment" /> </id> <discriminator column="party_type"></discriminator> <property name="name" /> <property name="sn" /> <many-to-one name="parent" column="pid" class="Party" cascade="all"/> <set name="children" cascade="all"> <key column="pid"/> <one-to-many class="Party" /> </set> <subclass name="Person" discriminator-value="P"> <property name="job"/> </subclass> <subclass name="Company" discriminator-value="P"> <property name="tel"/> </subclass> </class> </hibernate-mapping>