【发布时间】:2012-03-30 14:48:03
【问题描述】:
我使用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
更奇怪的是异常日志只在日志文件中,浏览网站没有问题。
这是怎么回事?
【问题讨论】:
-
您是否在您的应用程序中进行线程处理?您能否显示设置 OpenSessionInViewInterceptor 的 applicationContext.xml/web.xml 的相关部分?查看导致抛出异常的代码区域也可能会有所帮助。
标签: java hibernate transactions lazy-loading open-session-in-view