Hibernate 实体层设计--Table per subclass

Hibernate 支持三种类型的继承方式:

-Table per concrete class

  . 表与子类之间的独立一对一关系

-Table per subclass

  . 每个子类对于一表, 并与主类共享主表

-Table per class hiberarchy

  . 表与类的一对多关系

 

Table per subclass

<hibernate-mapping package="org.lxh.hibernate04">
    <class name="TItem " table="TITEM ">
        <id name="id " column="ID " type="string ">
            <generator class="assigned " />
        </id>
        <property name="name " column="NAME" type="string" not-null="true" />
        <property name="manufacturer " column="MANUFACTURER" type="string" />
        <joined-subclass name="TBook " table="TBook ">
            <key column="ID "></key>
            <property name="pageCount " type="java.lang.Integer" column="pagecount "></property>
        </joined-subclass >
        <joined-subclass name="TDVD " table="TDvd ">
            <key column="ID "></key>
            <property name="regionCode " type="java.lang.String" column="regioncode "></property>
        </joined-subclass>
    </class>

 

TBook : private int pageCount

TDVD : private S

TItem :

    private String id ;
    private String name ;
    private String manufacturer ;

 

SQL:

-- 删除表
DROP TABLE TItem ;

DROP TABLE TBook ;

DROP TABLE TDVD ;

-- 创建表
CREATE TABLE TItem
(
    id varchar(32) not null primary key ,
    name varchar(20) not null ,
    manufacturer varchar(20)
) ;

CREATE TABLE TBook
(
    id varchar(32) not null primary key ,
    pagecount int
) ;

CREATE TABLE TDvd
(
    id varchar(32) not null primary key ,
    regioncode varchar(2)
) ;

-- 事务提交
commit ;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值