栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java Hibernate延迟加载

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java Hibernate延迟加载

示例数据表: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">


   
       
           
           
       

                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")。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/153556.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号