4 Replies Latest reply on Sep 20, 2011 12:26 PM by Shriharsh Mishra

    LazyInitializationException - Seam-managed Entity Manager - 15 min Idle Time

    Aimee Ukasick Newbie

      Seam 2.2.0.GA
      JBoss 4.2.3.GA


      The session timeout, conversation timeout, and SFSB timeout are set to 180 minutes.


      I access the page, which in the code starts a long-running conversation via the Begin annotation. The data on the page is provided by an Entity object that has several collections (FetchType.LAZY) of other Entity objects. When I let the page sit idle for 15 minutes and then try to switch tabs, the app throws a LIE trying to load any collection that is displayed on the tab on which I clicked.
      The SFSB backing bean has ScopeType.CONVERSATION and @In private EntityManager entityManager.
      I thought that the extended persistence context functionality is implicit for a Seam-managed (or Seam-injected) EntityManager. Debug information shows the conversation is still active, yet the Hibernate session has been closed. How can that happen? Am I missing a setting somewhere? How can I prevent the LIE? The end users frequently leave the application idle for over 15 minutes during the work day.


      The  conversation that I explicitly started when the page was accessed is still active:



      13:32:34,382 INFO  [DebugHelperBean]  Conversation Context:
      13:32:34,382 INFO  [DebugHelperBean]   name: org.jboss.seam.pageflow.pageflow
      13:32:34,382 INFO  [DebugHelperBean]   name: org.jboss.seam.ui.EntityConverter
      13:32:34,382 INFO  [DebugHelperBean]   name: newRequestManager
      13:32:34,382 INFO  [DebugHelperBean]   name: org.jboss.seam.persistence.persistenceContexts
      13:32:34,382 INFO  [DebugHelperBean]   name: bpmService
      13:32:34,382 INFO  [DebugHelperBean]   name: debugHelper
      13:32:34,382 INFO  [DebugHelperBean]   name: org.jboss.seam.core.conversation
      13:32:34,382 INFO  [DebugHelperBean]   name: org.jboss.seam.international.statusMessages
      13:32:34,382 INFO  [DebugHelperBean]   name: org.jboss.seam.bpm.businessProcess
      13:32:34,382 INFO  [DebugHelperBean]   name: entityManager
      13:32:34,382 INFO  [DebugHelperBean]  CONVERSATION ENTRIES: 
      13:32:34,382 INFO  [DebugHelperBean]   Id=29
      13:32:34,382 INFO  [DebugHelperBean]   Description=null
      13:32:34,382 INFO  [DebugHelperBean]   ViewId=/product/createProductRequest.xhtml
      13:32:34,382 INFO  [DebugHelperBean]   Nested=false
      13:32:34,382 INFO  [DebugHelperBean]   Current=true
      13:32:34,382 INFO  [DebugHelperBean]   StartDatetime=Thu Jun 24 12:49:15 CDT 2010
      13:32:34,382 INFO  [DebugHelperBean]   LastDatetime=Thu Jun 24 13:32:32 CDT 2010
      13:32:34,382 INFO  [DebugHelperBean]   Timeout=10800000
      13:32:34,382 INFO  [DebugHelperBean]   ConcurrentRequestTimeout=1000





      web.xml:



      <session-config>
      <session-timeout>180</session-timeout><!--  minutes  -->
      </session-config>



      components.xml:



      <!-- 10800000 milliseconds = 180 minutes -->
      <!--  web.xml session timeout is 180 minutes -->
      <core:manager concurrent-request-timeout="1000"
           conversation-timeout="10800000"           
           conversation-id-parameter="cid"
           parent-conversation-id-parameter="pid" />
      <!-- Persistence -->
      <persistence:entity-manager-factory
           name="entityManagerFactory" 
           persistence-unit-name="TsseJ" />
      <persistence:managed-persistence-context
           auto-create="true" 
           entity-manager-factory="#{entityManagerFactory}"
           name="entityManager" />



      jboss-4.2.3.GA/server/default/conf/standardjboss.xml:



      <container-configuration>
      <container-name>Standard Stateful SessionBean</container-name>
            ... 
        <!-- see Seam 2.2.0.GA docs 30.8 Configuring SFSB and Session Timeouts in JBoss AS 
         -->
        <!-- SFSB timeout in seconds -->
         <!-- seam session timeout and conversation timeout is 180 minutes -->
         <max-bean-life>10800</max-bean-life>   
            ...     
              </container-configuration>     



      The backing bean:



      @Name("newRequestManager")
      @Scope(ScopeType.CONVERSATION)
      @Stateful
      @Restrict("#{identity.loggedIn}")
      public class NewRequestManagerBean implements NewRequestManager, TsseConstants,
                Serializable {





        • 1. Re: LazyInitializationException - Seam-managed Entity Manager - 15 min Idle Time
          Aimee Ukasick Newbie

          Stack Trace:



          13:32:34,163 ERROR [LazyInitializationException] failed to lazily initialize a collection of role: com.att.tsse.bo.ProductRequest.productRequestItems, no session or session was closed
          org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.att.tsse.bo.ProductRequest.productRequestItems, no session or session was closed
               at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380)
               at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372)
               at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:365)
               at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
               at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:272)
               at com.att.tsse.bo.ProductRequest.getOverallInitialCost(ProductRequest.java:191)
               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:597)
               at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
               at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
               at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
               at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
               at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
               at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
               at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
               at javax.faces.component.UIOutput.getValue(UIOutput.java:184)
               at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:201)
               at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:284)
               at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:154)
               at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
               at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:242)
               at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:178)
               at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:126)
               at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
               at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
               at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
               at org.ajax4jsf.renderkit.html.AjaxOutputPanelRenderer.encodeChildren(AjaxOutputPanelRenderer.java:78)
               at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
               at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
               at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
               at org.richfaces.renderkit.TabRendererBase.encodeChildren(TabRendererBase.java:113)
               at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
               at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
               at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
               at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:285)
               at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:280)
               at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
               at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
               at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:166)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157)
               at org.ajax4jsf.renderkit.AjaxContainerRenderer.encodeAjax(AjaxContainerRenderer.java:123)
               at org.ajax4jsf.component.AjaxViewRoot.encodeAjax(AjaxViewRoot.java:677)
               at org.ajax4jsf.component.AjaxViewRoot.encodeChildren(AjaxViewRoot.java:548)
               at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
               at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
               at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
               at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
               at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
               at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
               at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
               at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
               at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
               at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
               at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
               at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
               at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
               at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
               at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
               at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
               at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
               at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
               at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
               at java.lang.Thread.run(Thread.java:619)



          • 2. Re: LazyInitializationException - Seam-managed Entity Manager - 15 min Idle Time
            Aimee Ukasick Newbie

            and from persistence.xml:




            <persistence-unit name="TsseJ">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:/tsseDS</jta-data-source>
            <properties>
               <property name="hibernate.hbm2ddl.auto" value="validate" />
                 <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
                 <property name="hibernate.show_sql" value="false" />
                 <property name="hibernate.format_sql" value="true" />
                 <property name="jboss.entity.manager.factory.jndi.name"
                           value="java:/TsseJEntityManagerFactory" />
                 <property name="hibernate.transaction.manager_lookup_class"
                           value="org.hibernate.transaction.JBossTransactionManagerLookup" />
                 </properties>
            </persistence-unit>



            • 3. Re: LazyInitializationException - Seam-managed Entity Manager - 15 min Idle Time
              Shriharsh Mishra Newbie

              I am also facing the same problem. Did you find any solution?

              • 4. Re: LazyInitializationException - Seam-managed Entity Manager - 15 min Idle Time
                Shriharsh Mishra Newbie

                I found a solution for my problem. Hope it helps.


                In my application, ejbs are clustered and hence, were getting passivated after the default idle timeout of 300s.


                I change the configuration in the deploy/ejb3-interceptors-aop.xml,


                from -




                <domain name="Stateful Bean" extends="Base Stateful Bean" inheritBindings="true">
                .
                .
                .
                .
                 @org.jboss.ejb3.annotation.CacheConfig (maxSize=100000, idleTimeoutSeconds=300, removalTimeoutSeconds=0)
                .
                .
                .
                </domain>





                to -




                <domain name="Stateful Bean" extends="Base Stateful Bean" inheritBindings="true">
                .
                .
                .
                .
                
                 @org.jboss.ejb3.annotation.CacheConfig (maxSize=100000, idleTimeoutSeconds=900, removalTimeoutSeconds=0)
                
                .
                .
                .
                </domain>