java學(xué)習(xí)

          java學(xué)習(xí)

           

          hibernate中實(shí)體類(lèi)繼承,分成若干表

          父類(lèi)實(shí)體類(lèi):

          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;
           }
          }

          子類(lèi)實(shí)體類(lèi):

          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>
          在數(shù)據(jù)庫(kù)中表如下:

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


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


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

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 丽江市| 隆回县| 博爱县| 泸州市| 济宁市| 勃利县| 兴海县| 衡东县| 江口县| 白朗县| 温宿县| 阳曲县| 长垣县| 全椒县| 文成县| 海安县| 五华县| 马尔康县| 洛隆县| 南华县| 叙永县| 阜南县| 霍山县| 华亭县| 绿春县| 永定县| 青海省| 剑川县| 巴彦县| 读书| 县级市| 拜泉县| 百色市| 珠海市| 泽州县| 济阳县| 剑阁县| 西充县| 棋牌| 昌平区| 通州区|