一对多
例如:一个部门(Dept)有多个雇员(Emp)
在Dept类中配置 Set emps = new hashSet();
<Set name="emps">
<key column="deptno"></key>
<one-to-many class="com.web.bean.Emp"></one-to-many>
</Set>
多对一
例如:多个雇员对应一个部门
在Emp类中定义Dept dept = new Dept();
<many-to-one name="dept" class="com.web.bean.Dept" column="deptno"></many-to-one>
多对多
例如有三个表(product,orders,users)
多个产品有多个用户
在用户类中 Set products = new HashSet();
多个用户也可以购买多个产品
在产品类中 Set users = new HashSet();
在用户类的映射文件中,
<Set name="products" table="orders">
<key column="userid"></key>
<many-to-many class="com.web.bean.Product" column="pid"></many-to-many>
在product的映射文件中配置
<Set name="users" table="orders">
<key column="productid"></key>
<many-to-many class="com.web.bean.User" column="userid"></many-to-many>