自己做的笔记贴上来的,写的不好大家见谅
1.单向N-1关联:
在N的一端数据表中增加一个外键列,用于参照主表记录
<many-to-one name="" cascade="all" class="" column="" />
column指定外键列名
property-ref:当外键参照的是唯一键时需要指定
unique:唯一性约束、指定true时则为---->单向1-1关联
2.单向1-1关联:
基于外键的单向1-1关联:如上
3.单向1-N关联:<不推荐使用>
1>会使用两条SQL语句完成N端数据的插入:先是insert、再是update
2>使用的是1的一端控制关系,性能很低
无连接表:
<set name="">
<key column="" /> 指定关联的外键列
<one-to-many class=""/>
</set>
基于连接表:
<set name="" table="">
<key column="" /> 连接表中参照本表记录的外键列名
<many-to-many class="" unique="true"/>
</set>
4.单向N-N关联:必须使用连接表
<set name="" table="">
<key column="" /> 连接表中参照本表记录的外键列名
<many-to-many class="" />
</set>
5.双向1-N关联:
使用N的一端控制关联关系、需要指定以下配置中的两个列名相同
<set name="" inverse="true">
<key column="" /> 指定关联的外键列
<one-to-many class=""/>
</set>
<many-to-one name="" not-null="true" column="" />
6.双向N-N关联:必须使用连接表
table属性值必须相同
<set name="" table="" inverse="true">
<key column="" /> 连接表中参照本表记录的外键列名
<many-to-many class="" column=""/>
</set>
<set name="" table="">
<key column="" /> 连接表中参照本表记录的外键列名
<many-to-many class="" column=""/>
</set>
7.双向1-1关联:
<one-to-many class="" property-ref=""/>
只在此表中添加外键列
<many-to-one name="" unique="true" not-null="true" column="" />