get:Return the persistent instance of the given entity class with the given identifier, or
null if there is no such persistent instance. (If the instance, or a proxy for the
instance, is already associated with the session, return that instance or proxy.)
load:Return the persistent instance of the given entity class with the given identifier,
assuming that the instance exists.You should not use this method to determine
if an instance exists (use <tt>get</tt> * instead). Use this only to retrieve
an instance that you assume exists, where non-existence would be an actual error.
区别:
(1)如果未能发现符合条件的记录,get方法返回null,而load方法会抛出一个ObjectNotFoundException。
(2)load()方法可返回实体的代理类实例;而get方法永远直接返回实体类。
(3)load方法可以充分利用内部缓存(session缓存)和二级缓存中的现有数据,它将会使用代理来延迟加载该对象,然后当用到对象中的其他属性数据时才查询数据库,查找方式:load时会先查一下session缓存看看该id对应的对象是否存在,不存在则创建代理。所以当id对应的记录在据库中存在就可以使用load方法来实现延迟加载;而get方法则仅仅在内部缓存中进行数据查找,如没有发现对应数据,将越过二级缓存,直接调用SQL完成数据读取。
分享到:
相关推荐
spring HibernateTemplate汇总
hibernateTemplate的常用方法
HibernateTemplate的简单示例
HibernateTemplate的用法总结,我自己整理的,仅供参考
HibernateTemplate 的常规用法.doc HibernateTemplate 的常规用法.doc
关于使用HibernateTemplate
HibernateTemplate的方法部分使用,还有部分的个人见解,有错的,请指出,谢谢
对Spring框架中,HibernateTemplate的使用,底层dao中HibernateTemplate的使用以及HibernateCallBack调用等等
hibernateTemplate常用方法.htm
HibernateTemplat技术,此文档详细描述了HibernateTemplate的方法及功能说明,并有实例。
HibernateTemplate源代码
Spring整合hibernate(2)之基于HibernateTemplate的整合,jar需要自己添加!
GenericHibernateDao 继承 HibernateDao,简单封装 HibernateTemplate 各项功能,简化基于Hibernate Dao 的编写。
对于Hiberante对数据库种数据删除操作的归纳
HibernateTemplate类的使用
基于HIbernateTemplate的代码自动生成,能够自动生成dao和service文件,提高开发效率
JavaWeb开发,Sping框架,才用Hibernate Template进行字段截取,分组统计实现方法。
这是一个很好的文件,希望大家从中能找到自己的又用的部分,并且不断的进步
spring hibernatetemplate