//注解方法配置
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>