2

我正在使用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 

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

这是怎么回事?

4

2 回答 2

0

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

于 2012-05-21T06:55:10.993 回答
0

当您使用分离的对象时,通常会发生这种情况。您必须将对象重新附加到会话,以便 Hibernate 可以使用它。

使用session.merge()session.refresh()

这里你也有一些例子:在 Hibernate 中重新附加分离对象的正确方法是什么?

于 2012-04-11T03:43:05.477 回答