hibernate 继承映射

一,一个类继承体系一张表

 

<discriminator column="type" type="int"/>  <!--缺省:string(hibernate类型)-->

<subclass name="Skiller" discriminator-value="1">  <!--缺省:类的名称-->
    <property name="skill"/>
</subclass>
<subclass name="Sales" discriminator-value="2">
    <property name="sell"/>
</subclass>

 


<joined-subclass name="Skiller" table="skiller">
    <key column="emp_id"/>
    <property name="skill"/>
</joined-subclass>
<joined-subclass name="Sales" table="sales">
    <key column="emp_id"/>
    <property name="sell"/>
</joined-subclass>

 

 
<discriminator column="type" type="int"/>

<subclass name="Skiller" discriminator-value="1">
    <property name="skill"/>
</subclass>		
<subclass name="Sales" discriminator-value="2">
    <join table="sales">
        <key column="emp_id"/>
        <property name="sell"/>
    </join>
</subclass>

 

    主键不能使用native 生成策略,可以使用assigned

<class name="Employee" abstract="true"><!--abstract="true" 将不生产employee这张表-->
          <id name="id">
                         <generator class="assigned"/>
          </id>
 
<union-subclass name="Skiller" table="skiller">
    <property name="skill"/>
</union-subclass>
<union-subclass name="Sales" table="sales">
    <property name="sell"/>
</union-subclass>
 

 

 

 

 

 

你可能感兴趣的:(Hibernate)