lovezhou1990 2014-10-28 15:42 采纳率: 0%
浏览 2930
已采纳

spring mvc OpenSessionInViewFilter hibernate 懒加载问题

之前做了一个项目是使用 springmvc 加hibernate 做的, 并且使用了 hibernate 的懒加载有用到OpenSessionInViewFilter, 现在做另一个项目, 基础代码都是上个项目的代码;

目前调试在调试权限模块, 核对了上个项目的代码基本完全一致,但是这个项目的老是无法使用懒加载,加载报 org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.user.role.Role.menuRole, no session or session was closed, 和上个项目真的完全一致了, 包括事务都看过没问题,
下面是两个项目的log4j 日志, 是不一样的

-- 上个项目的日志
[DEBUG] [http-8088-2] org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
[DEBUG] [http-8088-2] org.hibernate.loader.Loader - result row: EntityKey[com.zmis.model.user.privilege.Role#297e26b04859021c01485902252d0004]
[DEBUG] [http-8088-2] org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
[DEBUG] [http-8088-2] org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[DEBUG] [http-8088-2] org.hibernate.engine.TwoPhaseLoad - resolving associations for [com.zmis.model.user.privilege.Role#297e26b04859021c01485902252d0004]
[DEBUG] [http-8088-2] org.hibernate.engine.TwoPhaseLoad - done materializing entity [com.zmis.model.user.privilege.Role#297e26b04859021c01485902252d0004]
[DEBUG] [http-8088-2] org.hibernate.engine.StatefulPersistenceContext - initializing non-lazy collections
[DEBUG] [http-8088-2] org.hibernate.loader.Loader - done entity load
[DEBUG] [http-8088-2] org.springframework.orm.hibernate3.HibernateTemplate - Not closing pre-bound Hibernate Session after HibernateTemplate

--- 现在这个项目的日志
[DEBUG] [http-8088-1] org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
[DEBUG] [http-8088-1] org.hibernate.loader.Loader - result row: EntityKey[com.zmis.model.user.role.Role#297e26b049520e6d0149520e746a000b]
[DEBUG] [http-8088-1] org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
[DEBUG] [http-8088-1] org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[DEBUG] [http-8088-1] org.hibernate.engine.TwoPhaseLoad - resolving associations for [com.zmis.model.user.role.Role#297e26b049520e6d0149520e746a000b]
[DEBUG] [http-8088-1] org.hibernate.engine.TwoPhaseLoad - done materializing entity [com.zmis.model.user.role.Role#297e26b049520e6d0149520e746a000b]
[DEBUG] [http-8088-1] org.hibernate.engine.StatefulPersistenceContext - initializing non-lazy collections
[DEBUG] [http-8088-1] org.hibernate.loader.Loader - done entity load
[DEBUG] [http-8088-1] org.springframework.orm.hibernate3.HibernateTemplate - Eagerly flushing Hibernate session
[DEBUG] [http-8088-1] org.hibernate.event.def.AbstractFlushingEventListener - processing flush-time cascades
[DEBUG] [http-8088-1] org.hibernate.event.def.AbstractFlushingEventListener - dirty checking collections
[DEBUG] [http-8088-1] org.hibernate.engine.Collections - Collection found: [com.zmis.model.user.role.Role.menuRole#297e26b049520e6d0149520e746a000b], was: com.zmis.model.user.role.Role.menuRole#297e26b049520e6d0149520e746a000b
[DEBUG] [http-8088-1] org.hibernate.engine.Collections - Collection found: [com.zmis.model.user.role.Role.usersRole#297e26b049520e6d0149520e746a000b], was: com.zmis.model.user.role.Role.usersRole#297e26b049520e6d0149520e746a000b
[DEBUG] [http-8088-1] org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
[DEBUG] [http-8088-1] org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 2 collections
[DEBUG] [http-8088-1] org.hibernate.pretty.Printer - listing entities:
[DEBUG] [http-8088-1] org.hibernate.pretty.Printer - com.zmis.model.user.role.Role{fid=297e26b049520e6d0149520e746a000b, inputDate=2014-10-27 22:41:59, roleKey=manager, px=null, usersRole=, remark=null, menuRole=, delete=false, active=true, roleName=管理员}
[DEBUG] [http-8088-1] org.springframework.orm.hibernate3.SessionFactoryUtils - Closing Hibernate Session
[DEBUG] [http-8088-1] org.hibernate.jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
[DEBUG] [http-8088-1] org.hibernate.jdbc.ConnectionManager - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!

  • 写回答

2条回答 默认 最新

  • lovezhou1990 2014-10-29 01:22
    关注

    有大神帮忙看看, 坐等回复;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已采纳回答 6月25日

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题