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 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗