12 Replies Latest reply on Oct 28, 2009 3:01 PM by eldiegolp

    javax.ejb.EJBException: Could not passivate; failed to save state

    pdhaigh

      Hi,


      I see the following error occur reasonably regularly in my logs. Once it does occur it happens every five minutes. Does anyone have any ideas what might be the cause, and resolution?



      2008-02-14 10:05:02,771 FATAL [org.jboss.serial.persister.RegularObjectPersister] error
      java.lang.reflect.InvocationTargetException
              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 org.jboss.serial.persister.RegularObjectPersister.writeSlotWithMethod(RegularObjectPersister.java:120)
              at org.jboss.serial.persister.RegularObjectPersister.defaultWrite(RegularObjectPersister.java:86)
              at org.jboss.serial.persister.RegularObjectPersister.writeData(RegularObjectPersister.java:62)
              at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:276)
              at org.jboss.serial.objectmetamodel.DataContainer$DataContainerDirectOutput.writeObject(DataContainer.java:206)
              at org.jboss.serial.persister.RegularObjectPersister.writeSlotWithFields(RegularObjectPersister.java:182)
              at org.jboss.serial.persister.RegularObjectPersister.defaultWrite(RegularObjectPersister.java:90)
              at org.jboss.serial.persister.RegularObjectPersister.writeData(RegularObjectPersister.java:62)
              at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:276)
              at org.jboss.serial.objectmetamodel.DataContainer$DataContainerDirectOutput.writeObject(DataContainer.java:206)
              at org.jboss.serial.persister.RegularObjectPersister.writeSlotWithFields(RegularObjectPersister.java:182)
              at org.jboss.serial.persister.RegularObjectPersister.defaultWrite(RegularObjectPersister.java:90)
              at org.jboss.serial.persister.RegularObjectPersister.writeData(RegularObjectPersister.java:62)
              at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:276)
              at org.jboss.serial.objectmetamodel.DataContainer$DataContainerDirectOutput.writeObject(DataContainer.java:206)
              at org.jboss.serial.persister.ArrayPersister.saveObjectArray(ArrayPersister.java:110)
              at org.jboss.serial.persister.ArrayPersister.writeData(ArrayPersister.java:101)
              at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:276)
              at org.jboss.serial.objectmetamodel.DataContainer$DataContainerDirectOutput.writeObject(DataContainer.java:206)
              at org.jboss.serial.io.JBossObjectOutputStream.writeObjectOverride(JBossObjectOutputStream.java:181)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:322)
              at org.jboss.serial.io.MarshalledObject.<init>(MarshalledObject.java:51)
              at org.jboss.ejb3.stateful.StatefulBeanContext.writeExternal(StatefulBeanContext.java:857)
              at org.jboss.serial.persister.ExternalizePersister.writeData(ExternalizePersister.java:58)
              at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:276)
              at org.jboss.serial.objectmetamodel.DataContainer$DataContainerDirectOutput.writeObject(DataContainer.java:206)
              at org.jboss.serial.io.JBossObjectOutputStream.writeObjectOverride(JBossObjectOutputStream.java:181)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:322)
              at org.jboss.ejb3.cache.simple.StatefulSessionFilePersistenceManager.passivateSession(StatefulSessionFilePersistenceManager.java:390)
              at org.jboss.ejb3.cache.simple.SimpleStatefulCache.passivate(SimpleStatefulCache.java:301)
              at org.jboss.ejb3.cache.simple.SimpleStatefulCache$SessionTimeoutTask.run(SimpleStatefulCache.java:209)
      Caused by: java.lang.NullPointerException
              at javax.faces.component.UIComponentBase.saveAttachedState(UIComponentBase.java:1342)
              at javax.faces.component.UIComponentBase.saveBindingsState(UIComponentBase.java:1450)
              at javax.faces.component.UIComponentBase.saveState(UIComponentBase.java:1241)
              at javax.faces.component.UIData.saveState(UIData.java:530)
              at javax.faces.component.html.HtmlDataTable.saveState(HtmlDataTable.java:883)
              at javax.faces.component.UIComponentBase$AttributesMap.writeObject(UIComponentBase.java:1763)
              ... 35 more




      2008-02-14 10:00:02,760 ERROR [ejb3.cache.simple.SimpleStatefulCache.ReportController] problem passivation thread
      javax.ejb.EJBException: Could not passivate; failed to save state
              at org.jboss.ejb3.cache.simple.StatefulSessionFilePersistenceManager.passivateSession(StatefulSessionFilePersistenceManager.java:406)
              at org.jboss.ejb3.cache.simple.SimpleStatefulCache.passivate(SimpleStatefulCache.java:301)
              at org.jboss.ejb3.cache.simple.SimpleStatefulCache$SessionTimeoutTask.run(SimpleStatefulCache.java:209)
      Caused by: java.io.IOException
              at org.jboss.serial.persister.RegularObjectPersister.writeSlotWithMethod(RegularObjectPersister.java:129)
              at org.jboss.serial.persister.RegularObjectPersister.defaultWrite(RegularObjectPersister.java:86)
              at org.jboss.serial.persister.RegularObjectPersister.writeData(RegularObjectPersister.java:62)
              at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:276)
              at org.jboss.serial.objectmetamodel.DataContainer$DataContainerDirectOutput.writeObject(DataContainer.java:206)
              at org.jboss.serial.persister.RegularObjectPersister.writeSlotWithFields(RegularObjectPersister.java:182)
              at org.jboss.serial.persister.RegularObjectPersister.defaultWrite(RegularObjectPersister.java:90)
              at org.jboss.serial.persister.RegularObjectPersister.writeData(RegularObjectPersister.java:62)
              at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:276)
              at org.jboss.serial.objectmetamodel.DataContainer$DataContainerDirectOutput.writeObject(DataContainer.java:206)
              at org.jboss.serial.persister.RegularObjectPersister.writeSlotWithFields(RegularObjectPersister.java:182)
              at org.jboss.serial.persister.RegularObjectPersister.defaultWrite(RegularObjectPersister.java:90)
              at org.jboss.serial.persister.RegularObjectPersister.writeData(RegularObjectPersister.java:62)
              at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:276)
              at org.jboss.serial.objectmetamodel.DataContainer$DataContainerDirectOutput.writeObject(DataContainer.java:206)
              at org.jboss.serial.persister.ArrayPersister.saveObjectArray(ArrayPersister.java:110)
              at org.jboss.serial.persister.ArrayPersister.writeData(ArrayPersister.java:101)
              at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:276)
              at org.jboss.serial.objectmetamodel.DataContainer$DataContainerDirectOutput.writeObject(DataContainer.java:206)
              at org.jboss.serial.io.JBossObjectOutputStream.writeObjectOverride(JBossObjectOutputStream.java:181)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:322)
              at org.jboss.serial.io.MarshalledObject.<init>(MarshalledObject.java:51)
              at org.jboss.ejb3.stateful.StatefulBeanContext.writeExternal(StatefulBeanContext.java:857)
              at org.jboss.serial.persister.ExternalizePersister.writeData(ExternalizePersister.java:58)
              at org.jboss.serial.objectmetamodel.ObjectDescriptorFactory.describeObject(ObjectDescriptorFactory.java:276)
              at org.jboss.serial.objectmetamodel.DataContainer$DataContainerDirectOutput.writeObject(DataContainer.java:206)
              at org.jboss.serial.io.JBossObjectOutputStream.writeObjectOverride(JBossObjectOutputStream.java:181)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:322)
              at org.jboss.ejb3.cache.simple.StatefulSessionFilePersistenceManager.passivateSession(StatefulSessionFilePersistenceManager.java:390)
              ... 2 more
      Caused by: java.lang.reflect.InvocationTargetException
              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 org.jboss.serial.persister.RegularObjectPersister.writeSlotWithMethod(RegularObjectPersister.java:120)
              ... 30 more
      Caused by: java.lang.NullPointerException
              at javax.faces.component.UIComponentBase.saveAttachedState(UIComponentBase.java:1342)
              at javax.faces.component.UIComponentBase.saveBindingsState(UIComponentBase.java:1450)
              at javax.faces.component.UIComponentBase.saveState(UIComponentBase.java:1241)
              at javax.faces.component.UIData.saveState(UIData.java:530)
              at javax.faces.component.html.HtmlDataTable.saveState(HtmlDataTable.java:883)
              at javax.faces.component.UIComponentBase$AttributesMap.writeObject(UIComponentBase.java:1763)
              ... 35 more


        • 1. Re: javax.ejb.EJBException: Could not passivate; failed to save state
          voreichel

          Hi Phil,


          could it be that one of your jsp/xhtml pages triggers a save operation in the background and meanwhile the session has expired?


          • 2. Re: javax.ejb.EJBException: Could not passivate; failed to save state
            pdhaigh

            Hi, thanks for the reply :)


            It is possible, although the error logged doesn't seem to give me any clues in tracking down what page/UI component might be causing it. Does it have to be a background operation, or would a user who's session timed out whilst on a page and then clicked something cause this?


            Do you know how I could find the page in question, or perhaps stop it trying  again every 5 mins?

            • 3. Re: javax.ejb.EJBException: Could not passivate; failed to save state
              voreichel

              Phil,


              I'm only guessing but the stacktrace shows:


                    

              at javax.faces.component.html.HtmlDataTable.saveState(HtmlDataTable.java:883)



              so I'd like to ask you to look for pages that use JSF/Richfaces data tables in your pages. This might be a starting point.


              Another approach in finding the exact cause might be to scan all files for the literal 300000 (5min = 5 * 60 seconds * 1000).
              If the cause to the error message is a periodic timer it will show up in a web page.
              If doubt that a user who's session has expired will fire an event every 5 minutes


              good luck!

              • 4. Re: javax.ejb.EJBException: Could not passivate; failed to save state
                pdhaigh

                Hi,


                Unfortunately most of my backend pages contain datatables! Ah well.


                I think the timing or retries must be automatic, because I haven't got that set anywhere.


                However, I've decided that a good option might be to turn on JSF fine-level logging temporarily, and see if I work out the culprit component from that. The downside is that the only place I see this error is in production, and turning on that level of logging will impact performance..


                As a further option I may update the JSF libs to 1.2.07


                Thanks for your help, will post any findings here!


                cheers


                phil

                • 5. Re: javax.ejb.EJBException: Could not passivate; failed to save state
                  gavin.king

                  Are you holding a reference to a JSF component from your SFSB?

                  • 6. Re: javax.ejb.EJBException: Could not passivate; failed to save state
                    pdhaigh

                    Hi gavin,


                    actually, yes:



                    <h:dataTable binding="#{reportController.dataTable}" value="#{month.bookings}" var="booking">



                    private HtmlDataTable dataTable;



                    and it's in SFSB that I'm doing rather dubious stuff in (in lieu of finding a decent design pattern):


                    the h:dataTable is in a jsf page that I want to open in Excel, with a dynamic filename:



                    public void runReport()
                    {
                         FacesContext ctx = FacesContext.getCurrentInstance();
                    
                         if (!ctx.getResponseComplete()) 
                         {
                              log.info("Running report: #0",report);
                    
                              String fileName ="Charity_Report"+sdf.format(expedition.getStartDate())+".xls";
                    
                              HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
                              response.setContentType("application/vnd.ms-excel");
                              response.setHeader("Content-Disposition","attachment;filename=\"" + fileName + "\""); 
                              ctx.renderResponse();
                    
                              // TODO This is a horrible, horrible non-solution (attempts to close report response after 5s)
                              maintenanceTasks.endResponse(5000L,ctx);
                         }
                    }
                    



                    The endReponse method calls:
                       


                    @Asynchronous
                    public void endResponse(@Duration Long duration,FacesContext ctx)
                    {
                         log.debug("Closing response on report");
                         ctx.responseComplete();
                    }     



                    ugh :-)


                    Is this likely what is causing the issue? (incidentally, I still can't reproduce it in testing environment - even by setting the session timeout to 1min).


                    If so, any suggestions as to what can I do? (or just a neat way to clean up my anti-pattern ;-) )

                    • 7. Re: javax.ejb.EJBException: Could not passivate; failed to save state
                      gavin.king

                      A JSF component is not serializable, so it can't be a field of an SFSB.

                      • 8. Re: javax.ejb.EJBException: Could not passivate; failed to save state
                        pdhaigh

                        Ah, good point :)


                        Can you recommend a good way of presenting a h:dataTable with row numbers, without binding it to a SFSB and using


                        <h:outputText value="#{reportController.dataTable.rowIndex + 1}"/>



                        Or should I just bind the component to a non-SFSB backing bean?


                        cheers


                        phil



                        • 9. Re: javax.ejb.EJBException: Could not passivate; failed to save state
                          christian.bauer
                          #{uiComponent['idOfYourDatatable'].rowIndex}

                          • 10. Re: javax.ejb.EJBException: Could not passivate; failed to save state
                            pdhaigh

                            Perfect, ta :)


                            (as a footnote, this doesn't work within ui:repeat but you can use



                            <h:dataTable value="#{mylist}" var="myobject">
                            <h:column>
                            #{mylist.indexOf(myobject)}
                            </h:column>
                            


                            )


                            • 11. Re: javax.ejb.EJBException: Could not passivate; failed to save state
                              eldiegolp

                              Hi, i have the same problem, could you solve this?


                              Thanks

                              • 12. Re: javax.ejb.EJBException: Could not passivate; failed to save state
                                eldiegolp

                                I have already solved it. I had a reference to FacesMessages and a webservice within my stateful EJB and did this:



                                @PrePassivate
                                        
                                public void ejbPassivate() throws EJBException, RemoteException {
                                                System.out.println("Passivating EJB");
                                                facesMessages = null;
                                                 webService = null;
                                }
                                
                                @PostActivate   
                                public void ejbActivate()throws EJBException, RemoteException {
                                                System.out.println("EJB reactivated ");
                                                
                                        }





                                Problems away....hope this help and thanks to the entire community