<hibernate-mapping > <class name="mypack.ClassA" table="TABLE_A" discriminator-value="A" > <id name="id" type="long" column="ID"> <generator class="increment"/> </id> <discriminator column="A_TYPE" type="string" /> <PRoperty name="a1" type="string" column="A1" /> <subclass name="mypack.ClassC" discriminator-value="C" > <property name="c1" column="C1" type="string" /> </subclass> <subclass name="mypack.ClassD" discriminator-value="D" > <property name="d1" column="D1" type="string" /> <subclass name="mypack.ClassG" discriminator-value="G" > <property name="g1" column="G1" type="string" /> </subclass> <subclass name="mypack.ClassH" discriminator-value="H" > <property name="h1" column="H1" type="string" /> </subclass> </subclass> </class> </hibernate-mapping>
<hibernate-mapping > <class name="mypack.ClassB" table="TABLE_B"> <id name="id" type="long" column="ID"> <generator class="increment"/> </id> <property name="b1" type="string" column="B1" /> <joined-subclass name="mypack.ClassE" table="TABLE_E"> <key column="B_ID" /> <property name="e1" column="E1" type="string" /> <property name="e2" column="E2" type="string" /> <property name="e3" column="E3" type="string" /> <property name="e4" column="E4" type="string" /> <property name="e5" column="E5" type="string" /> <property name="e6" column="E6" type="string" /> </joined-subclass > <joined-subclass name="mypack.ClassF" table="TABLE_F"> <key column="B_ID" /> <property name="f1" column="F1" type="string" /> <property name="f2" column="F2" type="string" /> <property name="f3" column="F3" type="string" /> <property name="f4" column="F4" type="string" /> <property name="f5" column="F5" type="string" /> <property name="f6" column="F6" type="string" /> </joined-subclass > </class> </hibernate-mapping>
ant -file build4.xml run
tx = session.beginTransaction();session.save(object);tx.commit();
ClassG g=new ClassG("a1","d1","g1");saveDO(g); ClassF f=new ClassF("b1","f1","f2","f3","f4","f5","f6","f7");saveDO(f);
insert into TABLE_A (ID,A1,D1,G1,A_TYPE) values (1, 'a1', 'd1', 'g1','G');
insert into TABLE_B (ID,B1) values (1, 'b1');insert into TABLE_F (B_ID ,F1, F2, F3, F4, F5, F6) values (1, 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7');
(出处:http://www.VeVb.com)
新闻热点
疑难解答