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 長春語林科技 閱讀(303) 評論(0)  編輯  收藏 所屬分類: hibernate
          <2008年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

           

          長春語林科技歡迎您!

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 黄陵县| 平阳县| 荆门市| 三河市| 彝良县| 张家川| 孙吴县| 颍上县| 长岭县| 铜川市| 肇庆市| 通许县| 苏尼特右旗| 潮州市| 辽宁省| 云阳县| 娱乐| 应城市| 景泰县| 益阳市| 宜川县| 专栏| 山阴县| 通许县| 勐海县| 山阳县| 定边县| 彩票| 保亭| 库尔勒市| 永康市| 新巴尔虎左旗| 界首市| 铜山县| 平谷区| 扶风县| 大丰市| 嘉义市| 平南县| 武川县| 墨江|