zoukankan      html  css  js  c++  java
  • hibernate的inverse,cascade

    /**
         * inverse:反转  
         *         inverse=false 表示将关系的维护交给被控方来维护(让人民记住国家主席)
         * cascade:级联
         *         cascade=all ,表示对象发生改变,它所关联的对象也会发生改变
         *    save-update,delete,none(不级联默认值)
         */
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC 
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    
    <hibernate-mapping package="cn.itcast.b_one2Many">
        <class name="Dept" table="t_dept">
            <id name="deptId">
                <generator class="native"></generator>
            </id>    
            <property name="deptName" length="20"></property>
            <!-- 
                一对多关联映射配置  (通过部门管理到员工)
                Dept 映射关键点:
                1.  指定 映射的集合属性: "emps"
                2.  集合属性对应的集合表: "t_employee"
                3.  集合表的外键字段   "t_employee. dept_id"
                4.  集合元素的类型
                inverse=false  set集合映射的默认值; 表示有控制权
             -->
             <set name="emps" cascade="save-update,delete" table="t_employee" inverse="true">   <!-- table="t_employee" -->
                  <key column="dept_id"></key>
                  <one-to-many class="Employee"/>
             </set>
        </class>
    </hibernate-mapping>
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC 
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    
    <hibernate-mapping package="cn.itcast.b_one2Many">
        <class name="Employee" table="t_employee">
            <id name="empId">
                <generator class="native"></generator>
            </id>    
            <property name="empName" length="20"></property>
            <property name="salary" type="double"></property>
            <!-- 
                多对一映射配置
                Employee 映射关键点:
                1.  映射的部门属性  :  dept
                2.  映射的部门属性,对应的外键字段: dept_id
                3.  部门的类型
             -->
             <many-to-one name="dept" column="dept_id" class="Dept"></many-to-one>
        </class>
    </hibernate-mapping>
  • 相关阅读:
    JS设置Cookie过期时间
    linq to xml
    ToDictionary的用法
    为程序使用内存缓存(MemoryCache)
    NuGet的几个小技巧
    IIS 的几个小技巧
    在Visual Studio中使用NuGet管理项目库
    在ASP.NET MVC中,使用Bundle来打包压缩js和css
    在C#中使用WMI查询进程的用户信息
    WMI测试器
  • 原文地址:https://www.cnblogs.com/lxh520/p/8125830.html
Copyright © 2011-2022 走看看