唯一外键 关联关系映射

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>

登录乐搏学院官网http://www.learnbo.com/

或关注我们的官方微博微信,还有更多惊喜哦~

唯一外键 关联关系映射

本文出自 “12691034” 博客,请务必保留此出处http://12701034.blog.51cto.com/12691034/1929252

转载于:https://my.oschina.net/learnbo/blog/914842