映射

一对一映射文件配置

  //主动方

   <one to one name="被动方实体类变量" class="被动方实体类路径" cascade="all"        property="关联类"/>

   EG:<one-to-one name="prove" class="com.li.www.entity.Prove" cascade="all" property-ref="student" />

  //被动方

   <many-to-one name="主动方实体类属性" class="主动方实体类路径" lazy="false" unique="true">

    <column name="主动方主键" />

    <many-to-one />

          EG: <many-to-one name="student" class="com.li.www.entity.Student" lazy="false" unique="true">

       <column name="SID"></column>

     </many-to-one>    

多对一映射文件配置

    <many-to-onev name="‘一’方实体类变量" class="‘一’方实体类路径">

     <column name="‘多’方所要关联的‘一’方的主键"></column>

    </many-to-one>

          EG: <many-to-one name="grade" class="com.li.www.entity.Grade">

       <column name="GID"></column>

     </many-to-one>     

一对多映射配置文件

     <set name="'多'方实体类变量">

      <key column="‘一’方所要关联的‘多’方的主键">

     <one-to-many class="‘多’方实体类路径"/>

           EG:<set name="students">

       <key column="GID" />

       <one-to-many class="com.li.www.entity.Student" />

   </set>

多对多映射文件配置

  //被动方

  <set>

      <set name="被动方实体类变量" table="关联表名称" cascade="save-update">

      <key column="所要关联主动方的主键" />

      <many-to-many class="被动方实体类路径" column="被动方主键"></many-tomany>

    </set>

          EG:<set name="students" table="course" cascade="save-update" inverse="true">

          <key column="cid"></key>

           <many-to-many class="com.li.www.entity.Student" column="sid"></many-to-many>

              </set>

   //主动方

  <set>

     <set name="主动方实体类变量" table="关联表名称" cascade="save-update"          inverse="true">

     <key column="所要关联被动方的主键" />

     <many-to-many class="主动方实体类路径" column="主动方主键"></many-tomany>

  </set>

          EG:<set name="courses" table="course" cascade="save-update">

               <key column="sid"></key>

               <many-to-many class="com.li.www.entity.Course" column="cid"></many-to-many>

        </set>

posted @ 2017-02-24 09:50  御姐萝莉轮番给我做饭  阅读(277)  评论(0编辑  收藏  举报