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 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?