java學(xué)習(xí)

          java學(xué)習(xí)

           

          hibernate中實(shí)體類繼承,按照子類建表

          實(shí)體類父類:

          public class Animal {
           
           private int id;
           
           private String name;
           
           private boolean sex;

           public int getId() {
            return id;
           }

           public void setId(int id) {
            this.id = id;
           }

           public String getName() {
            return name;
           }

           public void setName(String name) {
            this.name = name;
           }

           public boolean isSex() {
            return sex;
           }

           public void setSex(boolean sex) {
            this.sex = sex;
           }
          }

          子類:

          public class Bird extends Animal {

           private int height;

           public int getHeight() {
            return height;
           }

           public void setHeight(int height) {
            this.height = height;
           }
          }


          public class Pig extends Animal {
           
           private int weight;

           public int getWeight() {
            return weight;
           }

           public void setWeight(int weight) {
            this.weight = weight;
           }
          }


          extends.hbm.xml文件:
          <hibernate-mapping package="com.hibernate">
           <class name="Animal" abstract="true">
            <id name="id">
             <generator class="assigned"/>
            </id>
            <property name="name"/>
            <property name="sex"/>
            <union-subclass name="Pig" table="t_pig">
             <property name="weight"/>
            </union-subclass>
            <union-subclass name="Bird" table="t_bird">
             <property name="height"/>
            </union-subclass>
           </class>
          </hibernate-mapping>
          數(shù)據(jù)庫(kù)表如下:

          posted on 2013-05-07 09:46 楊軍威 閱讀(306) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 罗平县| 苏州市| 新乐市| 闸北区| 隆回县| 离岛区| 兴安盟| 哈尔滨市| 蒙城县| 获嘉县| 明星| 邓州市| 新源县| 阜城县| 琼中| 泰顺县| 乌拉特中旗| 弋阳县| 沛县| 大埔县| 永登县| 八宿县| 宁化县| 同仁县| 布拖县| 江华| 奉节县| 兴城市| 辽阳县| 姚安县| 缙云县| 南木林县| 杭州市| 福贡县| 阿坝| 巴彦淖尔市| 封开县| 拉萨市| 泾阳县| 称多县| 杂多县|