12 Replies Latest reply on Jun 30, 2010 6:43 PM by asookazian

    LazyInitializationException when rendering a result page

    phread.fbricon.gmail.com

      I'm developping a Seam 2.0.1GA application using JBoss AS 4.2.2.GA, EJB3 and RichFaces 3.1.4.GA.


      I have the following (simplified) search action :


      @Name("clientAction")
      
      @Stateful
      
      @Scope(ScopeType.SESSION)
      
      public class SimpleSearchClientAction implements RechercheClient
      
      {
      
        @Logger
      
        private static Log    log;
      
      
        @In
      
        private EntityManager entityManager;
      
      
        @In
      
        private FacesMessages facesMessages;
      
      
        @DataModel
      
        private List<Client>  clients;
      
      
        @DataModelSelection
      
        private Client        clientCourant;
      
      
        @Factory("clients")
      
        public void init()
      
        {
      
          log.debug("init client list ...");
      
          rechercher();
      
        }
      
      
        public void rechercher()
      
        {
      
          clients = entityManager.createQuery("select c from Client c").getResultList();
      
          if ((clients != null) && !clients.isEmpty())
      
          {
      
            facesMessages.add(FacesMessage.SEVERITY_INFO, "Trouvé #0 client(s)", clients.size());
      
          }
      
          else
      
          {
      
            facesMessages.add(FacesMessage.SEVERITY_INFO, "Aucun client");
      
          }
      
          log.debug("found #0 client(s)", clients.size());
      
        }
      
      
        @Remove
      
        @Destroy
      
        public void destroy()
      
        {
      
          // Nécessaire pour EJB Stateful
      
        }
      
      }
      
      



      The following table is rendered correctly when the page is accessed the first time :


      
       <rich:dataTable id="listeClients"   var="client"
      
                                  value="#{clients}"  rendered="#{not empty clients}"
      
                               columnClasses="col"
      
                               rows="15"
      
                               width="100%" 
      
                                 
      
                                    onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
      
                                    onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'">
      
                      <a4j:support event="onRowClick" action="/client/Ecr_Cli_2"></a4j:support>
      
                      <rich:column rendered="false">
      
                          <f:facet name="header">#{messages['Ecr_Cli_1_col.mutuelle']}</f:facet>
      
                          #{client.compagnieAssurance}
      
                      </rich:column>
      
                      <rich:column>
      
                          <f:facet name="header">#{messages['Ecr_Cli_1_col.num.client']}</f:facet>
      
                          #{client.numeroClient}
      
                      </rich:column>
      
                      <rich:column>
      
                          <f:facet name="header">#{messages['Ecr_Cli_1_col.civilite']}</f:facet>
      
                          #{client.personne.civilite.code}
      
                      </rich:column>
      
                      <rich:column>
      
                          <f:facet name="header">#{messages['Ecr_Cli_1_col.nom']}</f:facet>
      
                          #{client.personne.nom}
      
                      </rich:column>
      
                      <rich:column>
      
                          <f:facet name="header">#{messages['Ecr_Cli_1_col.prenom']}</f:facet>
      
                          #{client.personne.prenom}
      
                      </rich:column>
      
                      <rich:column>
      
                          <f:facet name="header">#{messages['Ecr_Cli_1_col.adresse']}</f:facet>
      
                          #{client.adresse.adresse} #{client.adresse.complementAdresse}
      
                      </rich:column>
      
                      <rich:column width="20px">
      
                          <f:facet name="header">#{messages['Ecr_Cli_1_col.code.postal']}</f:facet>
      
                          #{client.adresse.codePostal}
      
                      </rich:column>
      
                      <rich:column>
      
                          <f:facet name="header">#{messages['Ecr_Cli_1_col.ville']}</f:facet>
      
                          #{client.adresse.ville}
      
                      </rich:column>
      
                  </rich:dataTable>
      
                   <rich:spacer height="30" /> 
      
                  <rich:datascroller  styleClass="pagination"  for="listeClients" maxPages="5" rendered="#{not empty clients}"/>
      
                  
      
                  
      
                  <div class="filtreClient">
      
                          <h:outputText value="#{messages['Ecr_Cli_1_filtre.nom']}"/>
      
                          <h:inputText value="#{filtreClient.nom}"></h:inputText>           
      
                     </div>
      
                  
      
              <div class="toolbar" >
      
                    <table>
      
                      <tr>
      
                        <td>
      
                        <h:commandButton action="#{clientAction.rechercher()}"
      
                          value="#{messages['commons_filter.button']}"></h:commandButton>
      
                        </td>
      
                      </tr>
      
                    </table>
      
               </div>    
      
      



      However, if I click on the command button (clientAction.rechercher), i get the following exception :


      17:30:17,780 DEBUG [SimpleSearchClientAction] found 4 client(s)
      
      17:30:17,780 ERROR [LazyInitializationException] could not initialize proxy - no Session
      
      org.hibernate.LazyInitializationException: could not initialize proxy - no Session
      
           at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)
      
           at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
      
           at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:166)
      
           at com.monceauassurances.monceaunet.front.commun.ejb3.RSituationFamiliale_$$_javassist_2.equals(RSituationFamiliale_$$_javassist_2.java)
      
           at com.monceauassurances.monceaunet.front.commun.ejb3.PersonneEntity.equals(PersonneEntity.java:604)
      
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      
           at java.lang.reflect.Method.invoke(Unknown Source)
      
           at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:173)
      
           at com.monceauassurances.monceaunet.front.commun.ejb3.Personne_$$_javassist_125.equals(Personne_$$_javassist_125.java)
      
           at com.monceauassurances.monceaunet.front.commun.ejb3.ClientEntity.equals(ClientEntity.java:715)
      
           at java.util.AbstractList.equals(Unknown Source)
      
           at org.jboss.seam.databinding.DataModelBinder.isDirty(DataModelBinder.java:60)
      
           at org.jboss.seam.databinding.DataModelBinder.isDirty(DataModelBinder.java:14)
      
           at org.jboss.seam.Component.outjectDataModel(Component.java:1534)
      
           at org.jboss.seam.Component.outjectDataModels(Component.java:1519)
      
           at org.jboss.seam.Component.outject(Component.java:1471)
      
           at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:47)
      
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
      
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      
           at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:26)
      
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      
           at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:27)
      
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
      
           at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
      
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      
           at java.lang.reflect.Method.invoke(Unknown Source)
      
           at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
      
           at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
      
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
           at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
      
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
           at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
      
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
           at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
      
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
           at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
      
           at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
      
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
           at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
      
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
           at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
      
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
           at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
      
           at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
      
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
           at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
      
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
           at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
      
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
      
           at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:206)
      
           at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:119)
      
           at $Proxy117.rechercher(Unknown Source)
      
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      
           at java.lang.reflect.Method.invoke(Unknown Source)
      
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
      
           at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
      
           at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
      
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
      
           at org.jboss.seam.ejb.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:41)
      
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      
           at org.jboss.seam.core.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:32)
      
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
      
           at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
      
           at org.javassist.tmp.java.lang.Object_$$_javassist_7.rechercher(Object_$$_javassist_7.java)
      
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      
           at java.lang.reflect.Method.invoke(Unknown Source)
      
           at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
      
           at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:274)
      
           at org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59)
      
           at org.jboss.el.parser.AstMethodSuffix.invoke(AstMethodSuffix.java:65)
      
           at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
      
           at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
      
           at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
      
           at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
      
           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
      
           at javax.faces.component.UICommand.broadcast(UICommand.java:383)
      
           at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:184)
      
           at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:162)
      
           at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:350)
      
           at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
      
           at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
      
           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
      
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
      
           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.MultipartFilter.doFilter(MultipartFilter.java:85)
      
           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:141)
      
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
      
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
      
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
      
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      
           at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
      
           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:179)
      
           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(Unknown Source)



      If I remove the @Scope(ScopeType.SESSION), the page is displayed correctly, but the search method is called twice !!!


      Has anyone seen this issue?


      Regards,


      Fred B.

        • 1. Re: LazyInitializationException when rendering a result page
          nickarls

          And you are using a Seam-managed persistence context?


          Are you in a long-running conversation? Do you see the debug text from the init method when the search is called twice?

          • 2. Re: LazyInitializationException when rendering a result page
            phread.fbricon.gmail.com

            Yes I'm using a SMPC - if I'm not mistaken - here's my components.xml :



               <core:init debug="true" jndi-pattern="@jndiPattern@"/>
            
                 
            
               <core:manager concurrent-request-timeout="500" 
            
                             conversation-timeout="120000" 
            
                             conversation-id-parameter="cid"/>
            
                
            
               <persistence:managed-persistence-context name="entityManager"
            
                                                 auto-create="true"
            
                                  persistence-unit-jndi-name="java:/myEntityManagerFactory"/>
            
            
                 <transaction:ejb-transaction />
            
            
               <drools:rule-base name="securityRules">
            
                   <drools:rule-files>
            
                       <value>/security.drl</value>
            
                   </drools:rule-files>
            
               </drools:rule-base>
            
            
            
               <core:resource-loader><!-- Loads i18n application specific messages -->
            
                     <core:bundle-names>
            
                          <value>messages</value>
            
                         <value>commons</value>
            
                         <value>errors</value>
            
                     </core:bundle-names>
            
               </core:resource-loader>
            
            
            
               <security:identity authenticate-method="#{authenticator.authenticate}"
            
                                       security-rules="#{securityRules}"/>
            
               
            
               <event type="org.jboss.seam.notLoggedIn">
            
                   <action execute="#{redirect.captureCurrentView}"/>
            
               </event>
            
               <event type="org.jboss.seam.postAuthenticate">
            
                   <action execute="#{redirect.returnToCapturedView}"/>
            
               </event>
            
            



            I'm not using any conversation scopes - yet.


            When clientAction is declared using a @scope(SESSION), the init method is called once and for all, since clients is already in session after the first call. Only one search is executed when the button is clicked. The crash occurs when rendering the page.


            When no scope is declared, init() is called once per page rendering. So if I click on the button, the search method is called first during init(), since no clients component is available in any scope, then the actual search is performed.

            • 3. Re: LazyInitializationException when rendering a result page
              keithnaas

              Is Hibernate configured to use the SMPC?


              See 8.3.2. Using a Seam-managed Hibernate session

              • 4. Re: LazyInitializationException when rendering a result page
                phread.fbricon.gmail.com

                No, as you can see the components.xml in my previous message.


                Correct me if I'm wrong, but as I'm doing JPA/EJB3, I don't think I should have to configure Hibernate sessions (not according to 8.3.2. Using a Seam-managed Hibernate session)

                • 5. Re: LazyInitializationException when rendering a result page
                  keithnaas

                  Same question, different technology:


                  Is JPA also configured to use the SMPC?


                  See 8.3.1. Using a Seam-managed persistence context with JPA

                  • 6. Re: LazyInitializationException when rendering a result page
                    pmuir

                    SMPC doesn't prevent LIEs when used with Session scoped objects. Use a shorter scope like conversation or request or understand why this happens and initialize enough of the data graph to prevent this happening.

                    • 7. Re: LazyInitializationException when rendering a result page
                      infinity2heaven

                      had the same problem, the key is to use


                      @In private entityManager;


                      and not


                      @PersistenceContext entityManager;


                      Put it simply,
                      @In - it's intercepted, managed-by Seam, no more LIE
                      @PersistenceContext - injected by EJB container, you get LIE and lose out on all the nice things that Seam does for you.


                      Pete - I used Session scoped object (identical example as this post) and it worked fine, no LIE. Are you sure? And why?

                      • 8. Re: LazyInitializationException when rendering a result page
                        andygibson.contact.andygibson.net

                        The reason for LIEs on session scoped objects is that Session scoped objects become detached from the entity manager. The entity manager has at most a conversational scope, and your objects can last for hours or however long the user session is. When you render a page the entity is not attached to an entity manager with which to fetch more of the object graph.


                        As for why the search method is called twice when you decrease the scope, the problem there is probably related to the fact that the value is thrown away with the smaller scope and the factory needs to be called again to generate the data. Try using a page scope.

                        • 9. Re: LazyInitializationException when rendering a result page
                          vsarantchouk

                          Thanks Priya M for the tip; it worked. Looks like it's not a good idea to mix EJB-Container-managed persistence context with Seam-managed context.


                          We used entity manged injected by EJB container to manually flush the entities (which are also managed by Seam), and then use Seam redirect to a view which walks a lazy graph, we were getting could not initialize proxy - no Session LazyInitializationError. This was especially surprising because we are using Seam's long running conversations/transactions, which is supposed open a new HibernateSession when needed (e.g. when lazy entities are being accessed and need to be hydrated). The solution was:


                          1. Remove manual flashing of context (entityManager.flush()) - it's generally a bad idea to force JPA provider to write immediately.
                          Manual flush closes the transaction and HibernateSession, so persisted entities become detached; Seam appears to close the conversation as well, maybe it's a trigger in Seam's conversation lifecycle.


                          2. Change persistence context


                          from


                          @PersistenceContext entityManager; // managed by EJB container


                          to


                          @In private entityManager; // managed by Seam, which does many nice things on top of container services



                          Side note: it would be nice to know when exactly Seam start and commits a transaction; this is entirely hidden from a developer, unless you tun on debug level logging, which gives you way too much information.

                          • 10. Re: LazyInitializationException when rendering a result page
                            rkimiti
                            You can also try the following:

                            @PersistenceContext(type=PersistenceContextType.EXTENDED)

                            • 11. Re: LazyInitializationException when rendering a result page
                              asookazian

                              You will generally avoid LIEs when you use @In to inject the SMPC and @Begin(join=true,flushMode=FlushModeType.MANUAL).  The idea is to prevent the PC from being closed prior to the end of the LRC.  This will prevent the managed entities in the PC from being detached and then setting up a possible LIE scenario when the JSF view is rendered...

                              • 12. Re: LazyInitializationException when rendering a result page
                                asookazian

                                Remember that in order to use the manual flush, you must be using Hibernate as your persistence provider (this has not yet been standardized even in JPA2 spec).