標籤:
有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 繼承表結構