views:

87

answers:

2

Hello there,

I too have the same situation and i had configured the OpenSessionInViewFilter like this in my web.xml.

<!-- Hibernates session management for request -->
 <filter>
  <filter-name>hibReqSessionFilter</filter-name>
  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>hibReqSessionFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

but still im getting the same error

[12/7/09 4:22:17:968 EST] 0000001e WebApp        E   [Servlet Error]-[springweb]: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
 at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:132)
 at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:174)
 at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
 at com.moodys.mspg.model.MspgLkpAnalyst_$$_javassist_5.getAnalystId(MspgLkpAnalyst_$$_javassist_5.java)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:615)
 at org.apache.commons.el.ArraySuffix.evaluate(ArraySuffix.java:314)
 at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
 at org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:263)
 at org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:190)
 at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:754)
 at com.ibm._jsp._deallist._jspx_meth_c_out_10(_deallist.java:302)
 at com.ibm._jsp._deallist._jspx_meth_c_forEach_0(_deallist.java:375)
 at com.ibm._jsp._deallist._jspService(_deallist.java:97)
 at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:87)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1095)
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1036)
 at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:118)
 at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
 at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:832)
 at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:679)
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:565)
 at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
 at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:122)
 at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:226)
 at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.handleRequest(AbstractJSPExtensionProcessor.java:285)
 at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:321)
 at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:236)
 at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:257)
 at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1183)
 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:902)
 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
 at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1095)
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1036)
 at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:145)
 at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
 at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
 at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
 at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:832)
 at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:679)
 at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:565)
 at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
 at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3440)
 at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
 at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:815)
 at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1461)
 at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:118)
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:387)
 at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:267)
 at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
 at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
 at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
 at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
 at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
 at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
 at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
 at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
 at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
 at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1473)

if i knock off this filter and use lazy="false" in my orm xmls it works as expect.

But i want the things to be lazy loaded. Could any body help me in getting this achived

many thanks in advance

+1  A: 

Do you load the entity in the same session/during the same request? If not, you are trying to lazily load a collection on a detached entity (i.e. the entity's session has been closed), which will result in a LazyInitializationException.

If the entity you're displaying has been loaded during a previous request, you should be able to reload it from the database so it is then associated with the current Hibernate session.

(For a short explanation of managed/detached entities, see my answer to this unrelated question.)

Edit based on comment: Hm, in that case, my magic ends here. The exception is clear – there is no open session at the time you try to load the collection. If you really don't store the entity in the session somewhere, maybe because you're going through a POST/redirect/GET cycle, then I can only advise that you step through OpenSessionInViewFilter.doFilterInternal() with the debugger to see what's going on there. Good luck!

Henning
Thanks for your response Henning .It was creating problem for a single request only.I got to project one column which exists in one to many realtion ship with my entity (which is causing this error). If i intorduce the lazy="false" statement it works. But i want it to lazy loaded.Please help
Shivaji
A: 

spring will look for session factory in your application context, default the name is sessionFactory. Please configure the name for OpenSessionInViewFilter if you don't use the default name.

stinghu