posts - 325,  comments - 25,  trackbacks - 0
          為了持久化類之間的繼承關系映射到數據庫中,可以采用為每個具體的子類對應一個關系表,沒有父類數據表
          數據表:
          customer:
          id int(4) <pk>
          name varchar(20)
          phone varchar(20)

          oneoffOrders:一次性付款訂單表
          id int(4)  <pk>
          customer_id int(4)
          orderno varchar(20)
          moeny decimal(10,2)
          rebate decimal(10,2) 折扣金額

          dividedOrders:分期付款訂單表
          id int(4) <pk>
          customer_id int(4)
          moeny decimal(10,2)
          rebate decimal(10,2)
          months int(4)

          持久化類:
          public class Customer implements Serializable{
              private Integer id;
              private String name;
              private String phone;
              private Set orders=new HashSet();
              pulic Customer(){
              }
          }
          //父類
          public abstrace class Orders{
              private Integer id;
              private String orderno;
              private Double moeny;
              private Customer customer;
              public Orders(){
              }
          }
          //子類 Oneofforders
          public class Oneofforders extends Orders implements Serializable{
              private Double rebate;
              public Oneofforders(){
              }
          }
          //子類 Dividedorders
          public class Dividedorders extends Orders implements Serializable}
              private Integer months;
              public Dividedorders(){
              }
          }
          hbm.xml
          <hibernate-mapping package="com.lhb.vo">
              <class name="Customer" table="customer">
                  <id name="id" column="id" type="integer">
                      <generator class="native"/>
                  </id>
                  <property name="name" column="name" type="string"/>
                  <property name="phone" column="phone" type="string"/>
                  <set name="orders" lazy="false"  cascade="all" inverse="true">
                      <key column="customer_id"/>
                      <one-to-many class="com.lhb.vo.Orders"/>
                  </set>
              </class>
          </hibernate-mapping>
          <hibernate-mapping package="com.lhb.vo">
              <class name="Oneofforders" table="oneofforders">
                  <id name="id" column="id" type="integer">
                        <generator class="native"/>
                  </id>
                  <property name="orderno" column="orderno" type="string"/>
                  <property name="ordername" column="ordername" type="string"/>
                  <property name="rebate" column="rebate" type="double"/>
                  <many-to-one name="customer" column="customer_id" class="com.lhb.vo.Customer" lazy="false" not-null="true"/>
              </class>
          </hibernate-mapping>
          <hibernate-mapping package="com.lhb.vo">
              <class name="Dividedorders" table="dividedorders">
                  <id name="id" column="id" type="integer">
                      <generator class="native"/>
                  </id>
                  <property name="orderno" column="orderno" type="string"/>
                  <property name="money" column="money" type="double"/>
                  <proerty name="months" column="months" type="double"/>
                  <many-to-one name="customer" column="customer_id" class="com.lhb.vo.Customer" lazy="false" not-null="true"/>
              </class>
          </hibernate-mapping>
          posted on 2008-05-25 21:32 長春語林科技 閱讀(306) 評論(0)  編輯  收藏 所屬分類: hibernate
          <2008年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

           

          長春語林科技歡迎您!

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 东乡| 乡城县| 南江县| 庄河市| 武城县| 土默特右旗| 荃湾区| 信阳市| 淮阳县| 宝坻区| 磴口县| 临沂市| 乐陵市| 平安县| 阿克苏市| 北京市| 措美县| 中西区| 金昌市| 大竹县| 美姑县| 襄汾县| 江孜县| 本溪市| 金沙县| 泊头市| 南召县| 旌德县| 江阴市| 岑巩县| 平塘县| 当涂县| 长阳| 建瓯市| 崇州市| 东兰县| 米易县| 双柏县| 巴青县| 恩平市| 泸水县|