首页 > 代码库 > hibernate级联配置
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>
hibernate级联配置