• 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>
    ------------------------------------------------------------------------
    ------------------------------------------------------------------------

  • 相关阅读:
    json转换成对象
    查看本机电脑的dns
    springboot整合jsp
    mysql DATE_FORMAT()函数用法
    checkbox全选反选
    mysql 中GROUP_CONCAT使用
    checkeds 选中获取tbale表格中某一列td标签中的值
    工具方法整理
    java开发微信公众号支付(JSAPI)
    Could not create connection to database server. Attempted reconnect 3 times. Giving up.错误
  • 原文地址:https://www.cnblogs.com/lyunyu/p/3616681.html
Copyright © 2020-2023  润新知