zoukankan      html  css  js  c++  java
  • hibernate 多对多关联映射

    多对多关联映射 需要添加一张数据表,用来关联 双方

    一,单向多对多关联映射

      1,在一端的bean类添加对方的属性

        如 Category类

          private Set<Item> items=new HashSet<Item>();

      2,修改该bean类对应的映射文件

        Category.hbm.xml

          <set name="items" table="CATEGORY_ITEM" >
            <key>
              <column name="C_ID" />
            </key>
            <many-to-many class="com.m01.n2n.Item" column="I_ID"></many-to-many>
          </set>

          name: 对应本类的属性 items; 

          table: 中间表; column的name : 指的是中间表中 指向本bean类的数据表的 外键

          class: 对面bean类的全命名;  column : 中间表中 指向对面bean类的数据表的 外键

          


    一, 双向多对多关联

      1,在一端的bean类添加对方的属性

        如 Category类

          private Set<Item> items=new HashSet<Item>();

         Item类

          private Set<Category> categorys=new HashSet<>();

      2,修改bean类对应的映射文件 

        Category.hbm.xml 

          <set name="items" table="CATEGORY_ITEM" >
            <key>
              <column name="C_ID" />
            </key>
            <many-to-many class="com.m01.n2n.Item" column="I_ID"></many-to-many>
          </set>

          name: 对应本类的属性 items; 

          table: 中间表; column的name : 指的是中间表中 指向本bean类的数据表的 外键

          class: 对面bean类的全命名;  column : 中间表中 指向对面bean类的数据表的 外键

        Item.hbm.xml   

          <set name="categorys" table="CATEGORY_ITEM">
            <key>
              <column name="I_ID"></column>
            </key>
            <many-to-many class="com.m01.n2n.Category" column="C_ID"/>
          </set>

        同上;

  • 相关阅读:
    背景图片拉伸显示CSS
    可序列化对象和byte[]数组之间的互转
    简单web性能测试工具——ab命令(ApacheBench)
    测试人员必须掌握的linu常用命令
    robot framework 如何处理循环条件下面的变量自增
    robot framework 的关键字Continue For Loop 用法
    robot framework 的AutoItLibrary常用关键字
    robot framework 关键字Switch Browser和Select Window的区别
    robot framework 接口测试 http协议post请求json格式
    robot framework 怎么验证搜索无记录,页面元素不存在
  • 原文地址:https://www.cnblogs.com/m01qiuping/p/6384782.html
Copyright © 2011-2022 走看看