您的位置:首页 > 其它

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: