getHibernateTemplate.load() 和get()之间的区别
2014-03-14 08:58
447 查看
主要的地方:getHibernateTemplate.load() 存在延迟加载问题。
getHibernateTemplate.get() 不存在此问题,她是不采用lazy机制的。1 当记录不存在时候,get方法返回null,load方法产生异常,即get()可以取空的数据集,但load()不行。
take a look at the Hibernate documentation (though I agree is not very explicit)--the HibernateTemplate is basically a wrapper around the native Hibernate API.
get() will return null if an object is not found while load() will always return a non-null object which is a proxy. If the underlying object does not exist, the proxy will thrown ObjectNotFoundException.
load() should be used when you are sure that the object exits while get() when
you're not. 2 load方法可以返回实体的代理类,get方法则返回真是的实体类3 load方法可以充分利用hibernate的内部缓存和二级缓存中的现有数据,而get方法仅仅在内部缓存中进行数据查找,如果没有发现数据則将越过二级缓存,直接调用SQL查询数据库。4 也许别人把数据库中的数据修改了,load如何在缓存中找到了数据,则不会再访问数据库,而get则会返回最新数据。
转载地址:http://hi.baidu.com/sofent/item/2b8c9304221797d21ff046ee
getHibernateTemplate.get() 不存在此问题,她是不采用lazy机制的。1 当记录不存在时候,get方法返回null,load方法产生异常,即get()可以取空的数据集,但load()不行。
take a look at the Hibernate documentation (though I agree is not very explicit)--the HibernateTemplate is basically a wrapper around the native Hibernate API.
get() will return null if an object is not found while load() will always return a non-null object which is a proxy. If the underlying object does not exist, the proxy will thrown ObjectNotFoundException.
load() should be used when you are sure that the object exits while get() when
you're not. 2 load方法可以返回实体的代理类,get方法则返回真是的实体类3 load方法可以充分利用hibernate的内部缓存和二级缓存中的现有数据,而get方法仅仅在内部缓存中进行数据查找,如果没有发现数据則将越过二级缓存,直接调用SQL查询数据库。4 也许别人把数据库中的数据修改了,load如何在缓存中找到了数据,则不会再访问数据库,而get则会返回最新数据。
转载地址:http://hi.baidu.com/sofent/item/2b8c9304221797d21ff046ee
相关文章推荐
- hive深度理解与调优
- 入门---1.4: 探究SQL映射语句
- PowerHA 简介【转】
- 能时刻查询火车是否晚点的网站
- 当RPM包安装遇上“依赖性”问题时的解决办法
- Ubuntu下安装ruby
- Struts2值栈的理解【转】
- 理清需求的层次(软件需求管理二)
- 7款HTML5/CSS3应用新鲜出炉 功能强大实用 (www.html5tricks.com)
- Lucene 4 和 Solr 4 学习笔记
- 拷贝构造函数与赋值函数
- 解决使用jquery esayUI是重复加载
- android 开发之activity之间传递数据
- 清理任务栏残留图标Delphi版 附源程序 .
- 配置windows 2008 R2远程桌面授权,激活授权许可服务器
- 修复Win7文件夹内左侧内容消失文件夹左移显示异常(图)
- solr的facet性能
- jquery 事件对象属性小结
- 跨浏览器的本地存储解决方案
- VIPS:基于视觉的页面分割算法[微软下一代搜索引擎核心分页算法]