zoukankan      html  css  js  c++  java
  • Hibernate 的*.hbm.xml文件的填写技巧

      

    =================================================================================

    模板

    <!-- ?属性,本类与?类的多对多的关系 -->

    <set name="第一个问号值" table="中间表(类名_对方类名 或 对方类名_类名)其中两个地方的要一样">
    <key column=" (本类的名字+Id) "></key>
    <many-to-many class="第二个问号值" column="(对方的key里面的column属性的值)"></many-to-many>
    </set>

    <!-- ?属性,本类与?类的多对一的关系 -->
    <many-to-one name="(第一个问号的值)" class="(第二个问号的值)" column="(name的属性名 + Id)"></many-to-one>

    <!-- ?属性,本类与?类的一对多 -->
    <set name="(第一个问号的值)">
    <key column="(与其关联(多对一中)的类的column的值) "></key>
    <one-to-many class="(第二个问号的值)" />
    </set>


    ==================================================================================

    -------------------------------------------------------------------------------------------------------------------

    eg:

    -------------------------------------------------------------------------------------------------
    <!-- department属性,本类与Department的多对一 -->
    <many-to-one name="department" class="Department" column="departmentId"></many-to-one>


    <!-- roles属性,本类与Role的多对多 -->
    <set name="roles" table="itcast_user_role">
    <key column="userId"></key>
    <many-to-many class="Role" column="roleId"></many-to-many>
    </set>


    <!-- users属性,本类与User的一对多 -->
    <set name="users">
    <key column="departmentId"></key>
    <one-to-many class="User" />
    </set>
    ---------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------------------
    <!-- parent属性,本类与Department(上级)的多对一 -->
    <many-to-one name="parent" class="Department" column="parentId"></many-to-one>


    <!-- children属性,本类与Department(下级)的一对多 -->
    <set name="children">
    <key column="parentId"></key>
    <one-to-many class="Department" />
    </set>
    ---------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------


    <!-- users属性,本类与User的多对多 -->
    <set name="users" table="itcast_user_role">
    <key column="roleId"></key>
    <many-to-many class="User" column="userId"></many-to-many>
    </set>
    ------------------------------------------------------------------------
    ------------------------------------------------------------------------

  • 相关阅读:
    关于dllimport的使用
    公众平台返回原始数据为: 错误代码-40164
    CentOS7.4 系统下 Tomcat 启动慢解决方法
    PyCharm实现高效远程调试代码
    代码比较工具推荐
    CentOS7 下源码安装 python3
    linux定时任务调度定系统——opencron
    使用 ISO镜像配置 本地yum 源(RHEL, CentOS, Fedora等适用)
    Error: rpmdb open failed
    部署Redis(脚本安装)
  • 原文地址:https://www.cnblogs.com/lyunyu/p/3616681.html
Copyright © 2011-2022 走看看