We test hibernate + spring framework ,we want to have lazyloading so we set SessionInView Filter Or Hibernate Interceptor ,we have not any problem when we read one object but when we want to read their related object (related collection) it gives lazy loading ERROR:
ERROR - LazyInitializationException.<init>(25) | Failed to lazily initialize a collection - no session or session was closed
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:209)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.size(Set.java:106)
at org.appfuse.web.CustomerAction.list(CustomerAction.java:96)
at org.appfuse.web.CustomerAction.unspecified(CustomerAction.java:169)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:291)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:231)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:131)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:449)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:264)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1176)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:454)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:731)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
WARN - RequestProcessor.processException(534) | Unhandled Exception thrown: class net.sf.hibernate.LazyInitializationException