在客户实体类中set 联系人的对象
//表示所有的联系人
private Set<LinkMan> setLinkMan = new HashSet<LinkMan>();
public Set<LinkMan> getSetLinkMan() {
return setLinkMan;
}
public void setSetLinkMan(Set<LinkMan> setLinkMan) {
this.setLinkMan = setLinkMan;
}
在联系人的类中声明客户对象
//所属客户
private Customer customer;
public Customer getCustomer() {
return customer;
}
配置映射关系
在Customer配置中
<!-- 表示客户所有联系人 -->
<set name="setLinkMan" inverse="true" cascade="delete">
<key column="clid"></key>
<one-to-many class="cn.itcast.entity.LinkMan"/>
</set>
在linkman的配置文件中
<!-- 联系人所属客户 -->
<many-to-one name="customer" class="cn.itcast.entity.Customer" column="clid"></many-to-one>
<mapping resource="cn/itcast/entity/User.hbm.xml"/>
<mapping resource="cn/itcast/entity/Customer.hbm.xml"/>
<mapping resource="cn/itcast/entity/LinkMan.hbm.xml"/>
<mapping resource="cn/itcast/entity/Visit.hbm.xml"/>
<mapping resource="cn/itcast/entity/Dict.hbm.xml"/>