lazy-Hibernate4懒加载失效 多次查询数据库

问题描述

Hibernate4懒加载失效 多次查询数据库

D-D 22:49:34,351 org.hibernate.SQL DEBUG select registrati0_.MemberId as MemberId3_1_, registrati0_.Id as Id1_, registrati0_.Id as Id4_0_, registrati0_.CreateTime as CreateTime4_0_, registrati0_.MemberId as MemberId4_0_, registrati0_.Name as Name4_0_, registrati0_.TrainingSchoolId as Training5_4_0_ from NDEP.dbo.Registrations registrati0_ where registrati0_.MemberId=?
D-D 22:49:34,351 org.hibernate.loader.Loader DEBUG Result set contains (possibly empty) collection: [com.mvc.frame.model.Members.registrationses#21]
D-D 22:49:34,351 internal.CollectionLoadContext DEBUG 1 collections were found in result set for role: com.mvc.frame.model.Members.registrationses
D-D 22:49:34,351 internal.CollectionLoadContext DEBUG Collection fully initialized: [com.mvc.frame.model.Members.registrationses#21]
D-D 22:49:34,351 internal.CollectionLoadContext DEBUG 1 collections initialized for role: com.mvc.frame.model.Members.registrationses
D-D 22:49:34,351 nal.StatefulPersistenceContext DEBUG Initializing non-lazy collections
D-D 22:49:34,351 org.hibernate.loader.Loader DEBUG Done loading collection
D-D 22:49:34,351 org.hibernate.loader.Loader DEBUG Loading collection: [com.mvc.frame.model.Members.memberBlacklistIpses#21]
D-D 22:49:34,351 org.hibernate.SQL DEBUG select memberblac0_.MemberId as MemberId3_1_, memberblac0_.id as id1_, memberblac0_.id as id2_0_, memberblac0_.CreateTime as CreateTime2_0_, memberblac0_.IpAddress as IpAddress2_0_, memberblac0_.MemberId as MemberId2_0_ from NDEP.dbo.MemberBlacklistIps memberblac0_ where memberblac0_.MemberId=?
D-D 22:49:34,351 org.hibernate.loader.Loader DEBUG Result set contains (possibly empty) collection: [com.mvc.frame.model.Members.memberBlacklistIpses#21]
D-D 22:49:34,351 internal.CollectionLoadContext DEBUG 1 collections were found in result set for role: com.mvc.frame.model.Members.memberBlacklistIpses
D-D 22:49:34,351 internal.CollectionLoadContext DEBUG Collection fully initialized: [com.mvc.frame.model.Members.memberBlacklistIpses#21]
D-D 22:49:34,351 internal.CollectionLoadContext DEBUG 1 collections initialized for role: com.mvc.frame.model.Members.memberBlacklistIpses
D-D 22:49:34,351 nal.StatefulPersistenceContext DEBUG Initializing non-lazy collections
D-D 22:49:34,351 org.hibernate.loader.Loader DEBUG Done loading collection
D-D 22:49:34,351 estResponseBodyMethodProcessor DEBUG Written [com.mvc.common.bean.SearchResult@4f2ce7fa] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter@d31f6b2]
D-D 22:49:34,351 .web.servlet.DispatcherServlet DEBUG Null ModelAndView returned to DispatcherServlet with name 'springmvc': assuming HandlerAdapter completed request handling
D-D 22:49:34,351 .web.servlet.DispatcherServlet DEBUG Successfully completed request
D-D 22:49:34,351 upport.OpenSessionInViewFilter DEBUG Closing Hibernate Session in OpenSessionInViewFilter
D-D 22:49:34,351 internal.LogicalConnectionImpl DEBUG Releasing JDBC connection
D-D 22:49:34,356 internal.LogicalConnectionImpl DEBUG Released JDBC connection
D-D 22:49:34,356 l.proxy.ConnectionProxyHandler DEBUG HHH000163: Logical connection releasing its physical connection
D-D 22:49:34,408 upport.OpenSessionInViewFilter DEBUG Using SessionFactory 'sessionFactory' for OpenSessionInViewFilter
D-D 22:49:34,409 ort.DefaultListableBeanFactory DEBUG Returning cached instance of singleton bean 'sessionFactory'
D-D 22:49:34,409 upport.OpenSessionInViewFilter DEBUG Opening Hibernate Session in OpenSessionInViewFilter
D-D 22:49:34,409 hibernate.internal.SessionImpl DEBUG Opened session at timestamp: 14196053744
D-D 22:49:34,409 upport.OpenSessionInViewFilter DEBUG Closing Hibernate Session in OpenSessionInViewFilter
D-D 22:49:34,416 upport.OpenSessionInViewFilter DEBUG Using SessionFactory 'sessionFactory' for OpenSessionInViewFilter
D-D 22:49:34,416 ort.DefaultListableBeanFactory DEBUG Returning cached instance of singleton bean 'sessionFactory'
D-D 22:49:34,416 upport.OpenSessionInViewFilter DEBUG Opening Hibernate Session in OpenSessionInViewFilter
D-D 22:49:34,416 hibernate.internal.SessionImpl DEBUG Opened session at timestamp: 14196053744
D-D 22:49:34,416 upport.OpenSessionInViewFilter DEBUG Closing Hibernate Session in OpenSessionInViewFilter

*******************hibernate实体****************************

@LazyCollection(LazyCollectionOption.TRUE)
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "members")
public Set<Registrations> getRegistrationses() {
    return this.registrationses;
}

public void setRegistrationses(Set<Registrations> registrationses) {
    this.registrationses = registrationses;
}

@LazyCollection(LazyCollectionOption.TRUE)
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "members")
public Set<MemberBlacklistIps> getMemberBlacklistIpses() {
    return this.memberBlacklistIpses;
}

public void setMemberBlacklistIpses(Set<MemberBlacklistIps> memberBlacklistIpses) {
    this.memberBlacklistIpses = memberBlacklistIpses;
}
时间: 2024-12-03 10:17:01

lazy-Hibernate4懒加载失效 多次查询数据库的相关文章

DWR 导致 Spring bean 懒加载失效 何解?

问题描述 spring 中配置 bean lazy-init="true"但是应用启动时bean还是被初始化,通过排除配置文件发现配置dwr后,懒加载就不起作用.请问下,有知道是什么原因么?去掉dwr配置,懒加载就起作用. <!--spring DWR配置 --> <dwr:configuration> <dwr:convert type="bean" class="org.hibernate.validator.engine

hibernate之xml映射文件关系维护,懒加载,级联

      一:关系维护   --->inverse默认值false,表示不放弃关系的维护.   --->inverse="true"配置在那一端,表示那一端xml对应的po放弃关系的维护(交由hibernate内部进行维护),由另一端进行关系维护.  例子:学生班级模型[多对一模型]一端放弃关系的维护,由学生端进行关系维护              ----->班级的xml映射文件中<set name="students" class=&q

Hibernate懒加载解析

Hibernate懒加载解析 在Hibernate框架中,当我们要访问的数据量过大时,明显用缓存不太合适, 因为内存容量有限 ,为了减少并发量,减少系统资源的消耗,这时Hibernate用懒加载机制来弥补这种缺陷,但是这只是弥补而不是用了懒加载总体性能就提高了. 我们所说的懒加载也被称为延迟加载,它在查询的时候不会立刻访问数据库,而是返回代理对象,当真正去使用对象的时候才会访问数据库.    实现懒加载的前提:  1 实体类不能是final的 2 能实现懒加载的对象都是被CGLIB(反射调用)改

hibernate 一对多映射 懒加载

   //从一的一端查询        //hibernate 默认使用懒加载       ClassRoom cr=(ClassRoom) session.get(ClassRoom.class, 1);//get方法不会懒加载,会直接查询ClassRoom数据库,       //但不会发出查询和他一对多的两个数据库的sql       cr.getStu();//默认设置,不会发出sql语句,在<class name="ClassRoom" table="t_cl

懒加载和预加载的实现

提到前端性能优化中图片资源的优化,懒加载和预加载就不能不说,下面我用最简洁明了的语言说明懒加载和预加载的核心要点以及实现 懒加载 什么是懒加载 懒加载也就是延迟加载;当访问一个页面时,先将img标签中的src链接设为同一张图片(这样就只需请求一次,俗称占位图),将其真正的图片地址存储在img标签的自定义属性中(比如data-src);当js监听到该图片元素进入可视窗口时,即将自定义属性中的地址存储到src属性中,达到懒加载的效果;这样做能防止页面一次性向服务器响应大量请求导致服务器响应慢页面卡顿

懒加载-OpenSessionInViewFilter 的配置问题

问题描述 OpenSessionInViewFilter 的配置问题 在hibernate4使用中,出现懒加载问题 但是在web.xml文件中,配置了 还是找不到Session 请问应该怎么处理??? 解决方案 http://wenku.baidu.com/link?url=ulLU1LIJ1bGvcQdjqHA7cudRVW1XhdatyQjVoQDBnaNYXKTA6gq_ETFgdkwYlEfTUv68taNB0FWD5OAQxZ202itXqbdaroCp34gVKeHjFZy

Struts2在打包json格式的懒加载异常问题

版权声明:尊重博主原创文章,转载请注明出处哦~http://blog.csdn.net/eson_15/article/details/51394302         hibernate中如果出现了级联查询,就可能出现懒加载问题,比如我现在有个Account(管理员)类.Category(商品类别)和Product(商品)类,从左到右都是一对多的关系,而且从右到左都是设置了@ManyToOne(fetch=FetchType.LAZY).我现在要把商品信息查出来打包成json格式传到前台,我在

hibernate懒加载能用get方法吗

问题描述 hibernate懒加载能用get方法吗 hibernate中的session.load()方法特性是使用懒加载,那么请问hibernate中的session.get()方法在什么情况下也是使用的懒加载?还是说get方法没有懒加载,都是立即加载?看教程的时候发现测试集合的懒加载是用get方法取一对多的一对象而不是load方法 解决方案 http://blog.csdn.net/yaorongwang0521/article/details/7074573 解决方案二: get和load

lazy-hibernate 懒加载机制及抓取策略

问题描述 hibernate 懒加载机制及抓取策略 org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.gycn.model.Hotel.roomTypes, no session or session was closed 出现这种情况是因为用了懒加载,但是有的地方需要加载集合,有的地方则不用,那么lazy这个属性到底要怎么设置呢? 解决方案 抓取策略应