Hibernate 繼承表結構

來源:互聯網
上載者:User

標籤:

有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 1start with 1nomaxvalue nominvalue nocache;CREATE  TRIGGER book_trigger BEFOREINSERT ON booktbl FOR EACH ROW WHEN(new.id is null)beginselect 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_seqincrement by 1start with 1nomaxvalue nominvalue nocache;CREATE TRIGGER clo_triggerbeforeINSERT ON clothestbl FOR EACH ROW WHEN(new.id is null)beginselect 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"/>

Hibernate 繼承表結構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.