对one-to-one 关系进行延迟加载和其他关系相比稍微有些不同。many-to-one 的延迟加载是在配置文件的class 标签
示例数据表:team(班级)、certificate(身份证)、student(学生)
Team.hbm.xml
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
lazy ="true" >
lazy="true" >
Certificate.hbm.xml
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
lazy="true" >
class="edu.dgut.ke.model.Student"
constrained="true" >
Student.hbm.xml
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
lazy="true" >
class="edu.dgut.ke.model.Certificate"
unique="true"
column="cardId"
cascade="all"
>
注意:对one-to-one 关系进行延迟加载和其他关系相比稍微有些不同。many-to-one 的延迟加载是在配置文件的class 标签
上设置 lazy="true" ,one-to-many 和 many-to-many 的延迟加载是在 set 标签中设置lazy="true"。而one-to-one 不只要在 classs
标签设置 lazy="true",而且要在one-to-one 标签中设置constrained="true" 。
如果不设置constrained="true",则一对一查询使用默认的预先抓取策略(fetch="join")。
Team.hbm.xml
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
Certificate.hbm.xml
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
constrained="true" >
Student.hbm.xml
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
unique="true"
column="cardId"
cascade="all"
>
注意:对one-to-one 关系进行延迟加载和其他关系相比稍微有些不同。many-to-one 的延迟加载是在配置文件的class 标签
上设置 lazy="true" ,one-to-many 和 many-to-many 的延迟加载是在 set 标签中设置lazy="true"。而one-to-one 不只要在 classs
标签设置 lazy="true",而且要在one-to-one 标签中设置constrained="true" 。
如果不设置constrained="true",则一对一查询使用默认的预先抓取策略(fetch="join")。
以上就是java Hibernate延迟加载的详细内容,更多请关注0133技术站其它相关文章!