hibernate继承策略

来源:互联网 发布:管道过滤器模式 java 编辑:程序博客网 时间:2024/04/26 12:29
beanpublic class Person {private Integer id;private String name;private Date birthday;} <pre name="code" class="java">public class Student extends Person{private Integer stu_id;private String college;private String course;        get and  set 略}
Person.hbm.xml  单表继承配置实现<!--单表继承子类和父类的数据都保存在同一张表中用的比较少,当子类比较少时可以这种继承策略 --><hibernate-mapping package="lee.bean"><class name="Person" table="t_person"><id name="id"><generator class="identity"/></id><discriminator type="string" column="sub_id"/><property name="name" /><property name="birthday" type="date"/><subclass name="Student"><property name="stu_id" /><property name="college" /><property name="course"/></subclass></class></hibernate-mapping>
<pre name="code" class="html">Person.hbm.xml  具体表继承配置实现
<!--具体表继承子类的扩展字段保存在子类对应的表中,子类继承的字段保存在父类对应的表中这种继承策略用的较多 --><hibernate-mapping package="lee.bean"><class name="Person" table="t_person"><id name="id"><generator class="identity"/></id><property name="name" /><property name="birthday" type="date"/><joined-subclass name="Student"><key column="f_id"/><property name="stu_id" /><property name="college" /><property name="course"/></joined-subclass></class></hibernate-mapping>

<pre name="code" class="html"><pre name="code" class="html">Person.hbm.xml  每个类对应一个表配置实现


<!--每个具体类一个表父类的字段数据保存在父类对应的表中子类的字段数据保存在子类对应的表中,包括子类继承的和扩展的 --><hibernate-mapping package="lee.bean"><class name="Person" table="t_person"><id name="id"><generator class="hilo"/> <!-- 高低算法主键生成策略 --></id><property name="name" /><property name="birthday" type="date"/><union-subclass name="Student"><property name="stu_id" /><property name="college" /><property name="course"/></union-subclass></class></hibernate-mapping>



0 0
原创粉丝点击