最近视频看的有点太快了,有的没有跟上做,嗨,现总结一下吧。
Hibernate上的lazy可以应用在一下标签上:
<class>取值为true/false
<property>取值为true/false
<set>取值为true/false/extra
<many-to-one><one-to-one>等单端关联,取值为false/proxy/noproxy
Lazy的实质是:再用到对象时才创建对象,对于Hibernate来说是发出sql语句。
Lazy的应用范围是在Session打开的情况下,据网上说有一个什么Sessionopeninview不知道是什么玩意,有空再看看,呵呵。
<class>上的lazy只对普通属性有影响,对于集合、单端关联等没有影响。
从网上摘得一句:“
测试类Hibernate Lazy:查id不发sql,因为你传的就是主键,查别的属性会发sql,Hibernate Lazy有效期必须是session在open时才可以,解决方式是使用openSessionInview。
测试集合Hibernate Lazy:get集合时不会发sql,迭代会发sql,查个数的时候会把整个集合查出来,这样的话对效率有影响。”好像有错误,就是应该是load集合,get是不支持lazy的,可能他所说的get并不是用get方法加载吧,而是单纯的用到get的意思吧,管他呢!
集合上的lazy设为extra时,在查询集合大小时,他不会将整个集合全部查询出来,而是select count(*) from ...这说明它是智能的,也是我们推荐使用的。
在单端关联上lazy=false,在访问普通属性时发出两条sql,查询属性以及对应的关联对象。
分享到:
相关推荐
博文链接:https://llying.iteye.com/blog/221699
博文链接:https://llying.iteye.com/blog/221700
博文链接:https://llying.iteye.com/blog/221701
hibernate映射lazy策略hibernate查询语言hql
Hibernate环境搭建 Hibernate主要接口 Hibernate主要映射 Hibernate的lazy、fetch、cascade等策略 Hibernate性能优化
020 、单端关联上的 lazy(懒加载)属性 021 继承关联映射 022 component(组件)关联映射 023 复合主键 关联映射 024 其它 关联映射 025 hibernate 悲观锁、乐观锁 026 hibernate 操作树形结构 027 hibernate 查询语言...
5.1.2 Hibernate访问持久化类属性的策略 5.1.3 在持久化类的访问方法中加入程序逻辑 5.1.4 设置派生属性 5.1.5 控制insert和update语句 5.2 处理SQL引用标识符 5.3 创建命名策略 5.4 设置数据库Schema...
19.1.7. 使用延迟属性抓取(Using lazy property fetching) 19.2. 二级缓存(The Second Level Cache) 19.2.1. 缓存映射(Cache mappings) 19.2.2. 策略:只读缓存(Strategy: read only) 19.2.3. 策略:读/...
hibernate的类级别检索策略和检索策略的lazy、fetch、batch-size属性使用
19.1.7. 使用延迟属性抓取(Using lazy property fetching) 19.2. 二级缓存(The Second Level Cache) 19.2.1. 缓存映射(Cache mappings) 19.2.2. 策略:只读缓存(Strategy: read only) 19.2.3. 策略:读/...
19.1.7. 使用延迟属性抓取(Using lazy property fetching) 19.2. 二级缓存(The Second Level Cache) 19.2.1. 缓存映射(Cache mappings) 19.2.2. 策略:只读缓存(Strategy: read only) 19.2.3. 策略:读/...
延迟初始化(延迟加载)(Lazy Initialization) 6.6. 集合排序(Sorted Collections) 6.7. 使用<idbag><br>6.8. 双向关联(Bidirectional Associations) 6.9. 三重关联(Ternary Associations) 6.10....
19.1.7. 使用延迟属性抓取(Using lazy property fetching) 19.2. 二级缓存(The Second Level Cache) 19.2.1. 缓存映射(Cache mappings) 19.2.2. 策略:只读缓存(Strategy: read only) 19.2.3. 策略:读/...
19.1.7. 使用延迟属性抓取(Using lazy property fetching) 19.2. 二级缓存(The Second Level Cache) 19.2.1. 缓存映射(Cache mappings) 19.2.2. 策略:只读缓存(Strategy: read only) 19.2.3. 策略:读/...
使用延迟属性抓取(Using lazy property fetching) 19.2. 二级缓存(The Second Level Cache) 19.2.1. 缓存映射(Cache mappings) 19.2.2. 策略:只读缓存(Strategy: read only) 19.2.3. 策略:读/写缓存...
* @GenericGenerator —— 注解声明了一个hibernate的主键生成策略。支持十三种策略。该注解有如下属性 * name 指定生成器名称 * strategy 指定具体生成器的类名(指定生成策略)。 * parameters 得到strategy指定的...
1. Hibernate入门 1.1. 前言 1.2. 第一部分 - 第一个Hibernate应用程序 1.2.1. 第一个class 1.2.2. 映射文件 1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第...
19.1.7. 使用延迟属性抓取(Using lazy property fetching) 19.2. 二级缓存(The Second Level Cache) 19.2.1. 缓存映射(Cache mappings) 19.2.2. 策略:只读缓存(Strategy: read only) 19.2.3. 策略:读/...
使用延迟属性抓取(Using lazy property fetching) 20.2. 二级缓存(The Second Level Cache) 20.2.1. 缓存映射(Cache mappings) 20.2.2. 策略:只读缓存(Strategy: read only) 20.2.3. 策略:读/写缓存...