关联映射
l 多对一(Employee- Department)
l 一对多(Department-Employee)
一对一(room - door)
多对多(teacher -student)
多对一(Employee - Department)
映射文件<many-to-one name=”depart” column=”depart_id”/>
ER图
一对多(Department-Employee)
<set name=”employees”>
<keycolumn=”depart_id”/>
<one-to-manyclass=”Employee”/>
</set>
一对一(Person -IdCard)
1)基于主键的one-to-one(person的映射文件)
<id name=”id”>
<generator class=”foreign”><paramname=”property”>idCard</param></generator>
<id>
<one-to-one name=”idCard” constrained=”true”/>
一对一(Person -IdCard)
2)基于外健的one-to-one,可以描述为多对一,加unique=“true”约束
<one-to-one name=”idCard” property-ref=“person”/>
property-ref用于指定关联类的一个属性,这个属性将会和本外键相对应
<many-to-one name=”person” column=”person_id” unique=”true”not-null=”true”/>
<!-唯一的多对一,其实就便成了一对一了-->