zoukankan      html  css  js  c++  java
  • Hibernate 继承表结构

    有Product , Book ,Clothes三张表

    Product:id,name

    Book:  id ,name,pageCount

    Clothes: id ,name ,size

    创建三张表

    产品表
    create table product(
        id number(2) primary key,
        name varchar2(10)
    );
    书表
    create table booktbl(
        id number(2) ,
        name    varchar2(10),
        pageCount    number(3),
        foreign key(id) references product(id)
    );
    create sequence book_seq 
    increment by 1
    start with 1
    nomaxvalue nominvalue nocache;
    
    CREATE  TRIGGER book_trigger BEFORE
    INSERT ON booktbl FOR EACH ROW WHEN(new.id is null)
    begin
    select book_seq.nextval into:new.id from dual;
    end;
    
    
    drop table  booktbl;
    drop sequence book_seq;
    brop trigger book_trigger;
    
    服装表
    create table clothestbl(
        id number(2) references product(id),
        name varchar2(10),
        closize number(5)
    );
    
    create sequence clothes_seq
    increment by 1
    start with 1
    nomaxvalue nominvalue nocache;
    
    CREATE TRIGGER clo_trigger
    before
    INSERT ON clothestbl 
    FOR EACH ROW 
    WHEN(new.id is null)
    begin
    select clothes_seq.nextval into:new.id from dual;
    end;
    
    
    drop table  clothestbl;
    drop sequence clothes_seq;
    brop trigger clo_trigger;

    Product.hlm.xml

      <class name="com.amaker.extendmodel.Product" table="Product">
               <id name="id">
                   <generator class="native"></generator>
               </id>
               <property name="name"></property>
               
                <joined-subclass name="com.amaker.extendmodel.Book" table="booktbl">         
                   <key column="id"></key>
                   <property name="pageCount"></property>
               </joined-subclass> 
               
                <joined-subclass name="com.amaker.extendmodel.Clothes" table="clothestbl">         
                   <key column="id"></key>
                   <property name="size" column="closize"></property>
               </joined-subclass> 
       </class> 

    <mapping resource="com/amaker/extendmodel/Product.hbm.xml"/>

  • 相关阅读:
    Rsync实现文件同步的算法(转载)
    Python模拟登录cnblogs
    负载均衡中四层和七层的介绍(转帖)
    Lvs+Keepalived实现MySQL高可用
    MySQL配置主主及主从备份
    Vim扩展YouCompleteMe插件
    使用Git
    Django回忆录
    Ansible安装配置及使用
    Hive学习之四 《Hive分区表场景案例应用案例,企业日志加载》 详解
  • 原文地址:https://www.cnblogs.com/da-peng/p/5903475.html
Copyright © 2011-2022 走看看