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" 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ù)庫表如下:

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


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


          網(wǎng)站導航:
           

          導航

          統(tǒng)計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 中江县| 交城县| 宜兴市| 衡阳市| 石棉县| 辽宁省| 永宁县| 抚远县| 舞钢市| 宜良县| 武邑县| 朝阳区| 河北省| 平凉市| 叙永县| 沙洋县| 舟山市| 呼伦贝尔市| 庆城县| 永和县| 南投县| 兴山县| 白城市| 禄丰县| 浦北县| 南江县| 清水河县| 遵化市| 新安县| 根河市| 汝阳县| 曲松县| 曲周县| 宿州市| 汕尾市| 湄潭县| 荔波县| 莫力| 乌兰浩特市| 柞水县| 澄江县|