java學習

          java學習

           

          hibernate中實體類繼承,分成若干表

          父類實體類:

          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" table="t_animal">
            <id name="id">
             <generator class="native"/>
            </id>
            <property name="name"/>
            <property name="sex"/>
            <joined-subclass name="Pig" table="t_pig">
             <key column="pid"/>
             <property name="weight"/>
            </joined-subclass>
            <joined-subclass name="Bird" table="t_bird">
             <key column="bid"/>
             <property name="height"/>
            </joined-subclass>
           </class>
          </hibernate-mapping>
          在數據庫中表如下:

          posted on 2013-05-07 09:37 楊軍威 閱讀(408) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 伊宁县| 黑龙江省| 大英县| 华安县| 平定县| 高尔夫| 灵璧县| 咸丰县| 景泰县| 长葛市| 吉木萨尔县| 黔西县| 西乌珠穆沁旗| 柞水县| 灯塔市| 舟山市| 九江县| 奈曼旗| 安徽省| 阳原县| 湾仔区| 沐川县| 邵阳市| 大石桥市| 寻甸| 福泉市| 盐亭县| 本溪市| 阜新| 通江县| 拜泉县| 陆良县| 宿松县| 乐至县| 双江| 明水县| 汶上县| 梓潼县| 雅江县| 澄江县| 铜梁县|