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>

        同上;

  • 相关阅读:
    图论专题1考试Problem1
    React 创建对话框组件
    React中防止字符转义
    JSX添加注释
    redux和react-redux在react中的使用
    动手实现 React-redux(三) Provider
    动手实现 React-redux(二) mapDispatchToProps
    动手实现 React-redux(一) connect 和 mapStateToProps
    Redux架构模式
    React context(不使用props,父组件给子组件传递信息)
  • 原文地址:https://www.cnblogs.com/m01qiuping/p/6384782.html
Copyright © 2011-2022 走看看