2.hibernate一对多的关系映射

多对多的关系映射

 

create table tb_teacher(

id number primary key,

name varchar2(50) not null

);

create table tb_student

(

id number primary key,

name varchar2(50) not null

);

create table tb_thtost

(

th_id number references tb_teacher(id),

st_id number references  tb_student(id),

primary key(th_id,st_id)

);

 

<class name="Teacher" table="tb_Teacher">

    <id name="id">

    <generator class="increment"/>

    </id>

    <property name="teachName" column="name"/>

    <set name="stuSet" table="tb_thtost" lazy="false">

    <key column="th_id"></key>

    <many-to-many class="Student" column="st_id"/>

    </set>

    </class>

   

    <class name="Student" table="tb_student">

    <id name="id">

    <generator class="increment"/>

    </id>

    <property name="stuName" column="name"/>

    <set name="teachSet" table="tb_thtost" lazy="false">

    <key column="st_id"/>

    <many-to-many class="Teacher" column="th_id"/>

    </set>

</class>

 

posted @ 2010-05-03 17:16  沉兮  阅读(176)  评论(0编辑  收藏  举报