<one-to-one name="student"
class="com.songjinghao.hibernate.Student"
fetch="select"></one-to-one>
</class>
总结:
一对一默认使用的是立即加载,如果需要使用延迟加载,那么需要在one-to-one
元素中将constrained 属性设为true,并且将待加载的一方的class元素中的lazy 属
性设为true(或者不去设置,因为该属性默认值就是true)。一对一加载时默认
使用左外连接,可以通过修改fetch属性为select修改成每次发送一条select语句的
形式。
2)外键关联
只需改动IdCard.hbm.xml文件:
<class name="com.songjinghao.hibernate.IdCard"
table="idCard">
<!--
<id name="id" column="id" type="string">
<generator class="foreign">
<param name="property">student</param>
</generator>
</id>
-->
<id name="id" column="id" type="string">
<generator class="uuid"></generator>
</id>
<property name="number" column="number"
type="integer"></property>
<!--
<one-to-one name="student"
class="com.songjinghao.hibernate.Student"
fetch="select"></one-to-one>
-->
<many-to-one name="student"
class="com.songjinghao.hibernate.Student"
column="student_id" unique="true"></many-to-one>
评论1
最新资源