posts - 247,  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 林的 阅读(224) 评论(0)  编辑  收藏 所属分类: hibernate

只有注册用户登录后才能发表评论。


网站导航:
 
<2008年5月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

想回家了,呵呵!

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

文章档案

相册

收藏夹

搜索

  •  

最新评论

阅读排行榜

评论排行榜