表间关联关联:
1. 一对多 单项关联 :
一端对多端 : 一端持有多端集合
xml配置 映射文件:
<!-- 一端持有多端集合 用set column 数据库外键 -->
<set name="emplyess">
<key>
<column name="did"/>
</key>
<one-to-many class="com.hst.usermanger.hibernate.model.Emplyess" />
</set>
2. 多对一 单项关联 :
多端对一端 : 多端持有一端实例
xml配置映射文件:
<!--多端持有一端 实例 column数据库 外键 -->
<many-to-one name="department" class="com.hst.usermanger.hibernate.model.Department">
<column name="did"/>
</many-to-one>
3. 多对一 双向项关联:
就是多对一单项与一对多单项
4.一对一单项关联 (唯一外键) 多对一特例
是多端对一端关联特例
加上 :一对一 <many-to-one uniqe=true/>
5.一对一双项关联 :
<one-to-one name="person" class="com.wisezone.hibernate.one.Person"/>
6.多对多关联:
<set name="courseLists" table="t_student_course"> <!--数据库 中间表名-->
<key>
<!-- 当前表student column属性值是student 表主键中间表对应字段 -->
<column name="s_id" />
</key>
<!-- many-to-many column属性值是course表主键在中间表对应字段 -->
<many-to-many class="com.wisezone.hibernate.many.Course" column="c_id"/>
</set>