有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java“未能延迟初始化角色集合”异常即使在我使用OSIV模式时也会发生

我使用OpenSessionInViewInterceptor来避免LazyInitializationException

它工作得很好,但从某个时候起,即使我使用OSIV,LazyInitializationException也会发生。例外情况如下:

SEVERE: Servlet.service() for servlet [appServlet] in context with path [] 
    threw exception [Request processing failed; nested exception is 
    org.apache.tiles.impl.CannotRenderException: ServletException including path 
    '/WEB-INF/views/home/master.jsp'.] with root cause org.hibernate.LazyInitializationException: 
    failed to lazily initialize a collection of role: com..., 
    no session or session was closed 
        at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersisten
tCollection.java:383)
        at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(Abs
tractPersistentCollection.java:375)
        at 

更奇怪的是,异常日志只存在于日志文件中,浏览网站没有问题

这是怎么发生的


共 (2) 个答案

  1. # 2 楼答案

    在我的例子中,这是因为缓存的对象。由于缓存对象被分离LazyInitializationException在访问某些属性时发生,这些属性稍后尚未初始化