zoukankan      html  css  js  c++  java
  • hibernate级联配置

    //注解方法配置

    1)一对多

    private List<TNoticeaffix> ffi;
    @OneToMany(cascade =CascadeType.ALL,mappedBy="T_NOTICE",targetEntity=TNoticeaffix.class)
    public List<TNoticeaffix> getFfi() {
    return ffi;
    }

    2)一对一(一对一和一对多的配置基本一样)

    private LTNoticeaffix ffi;
    @OneToMany(cascade =CascadeType.ALL,mappedBy="T_NOTICE",targetEntity=TNoticeaffix.class)
    public TNoticeaffix getFfi() {
    return ffi;
    }

    3)

    private Set<TMenu> menus= new HashSet<TMenu>();

    @ManyToMany
    @JoinTable(name="t_role_menu",joinColumns =@JoinColumn(name="rid"),inverseJoinColumns =@JoinColumn(name="mid"))
    public Set<TMenu> getMenus() {
    return menus;
    }

     

     2.配置文件方法

    1)一对多

    <set lazy="true" name="user" cascade="all" inverse="false" fetch="select" batch-size="2">
    <key column="userid"></key>
    <one-to-many class="cn.hd.onetomany.TUserconf"/>
    </set>

    2)一对一

    <!-- 主键关联 -->
    <one-to-one name="details" class="cn.hd.model.TUserdetails" ></one-to-one>
    <one-to-one name="conf" class="cn.hd.model.TUserconf" property-ref="user" cascade="save-update"></one-to-one>

     2)

    <!-- 多对一 -->
    <many-to-one name="dep" class="cn.hd.one2many.TDepartment" cascade="all">
    <column name="depid"></column>
    </many-to-one>

    3)多对多

    <set name="tuserconf" inverse="false" cascade="all" table="t_tuserconf_tuserdetailes">
    <key column="tai"></key>
    <many-to-many class="cn.hd.model.TUserconf" column="dir"></many-to-many>
    </set>

  • 相关阅读:
    [BTS] BizTalk host BizTalkServerApplication throttled because DatabaseSize exceeded the configured throttling limit.
    Linux sed 批量替换字符串方法
    MYSQL中的POSITION方法
    wc (Word Count)
    sudo
    关于数据库timestamp类型问题
    SQL中存储过程和自定义函数的区别
    数据库存储过程
    五 : springMVC拦截器
    四 : springMVC各种跳页面传值
  • 原文地址:https://www.cnblogs.com/joyous-day/p/6119675.html
Copyright © 2011-2022 走看看