4.1  搭建

1>表中   外键

2>实体中   关系属性

4.2 映射

<hibernate-mapping package="com.c40.one2oneUQ">

<class name="Student" table="t_student">

---<id name="id" type="java.lang.Integer">

<generator class="increment"></generator>

</id>

<!-- 

关系属性:com

1.关系属性名

2.关系对方

3.关系中的外键

one-to-one 默认行为:双方的主键相连,Student会默认连接Computer的id属性(所映射的列)

property-ref="stu":修改默认行为,告知Student应该连接Computer的stu属性(所映射的列)

4.级联

-->

---<one-to-one name="com" class="Computer" property-ref="stu"  cascade="none"></one-to-one>

</class>

<class name="Computer" table="computer">

---<id name="id" type="java.lang.Integer">

<generator class="increment"></generator>

</id>

---<many-to-one unique="true" name="stu" class="Student" column="stu_id" cascade="none"></many-to-one>

</class>