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日

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮