2 Replies Latest reply on Dec 21, 2015 6:56 AM by Bartosz Piotrowski

    Reconnecting to @Stateful EJB

    Bartosz Piotrowski Newbie

      Hello,

       

      I have a case where client communicating with WildFly (9.0.1.Final) using EJB Client library needs to reconnect to an EJB after the server was restarted. The problem is that I cannot reconnect to a Stateful session bean. Reconnecting to SLSBs work fine but is it even possible to reconnect to SFSB due to the session? Currently I get NoSuchEJBException: Could not find EJB with id UnknownSessionID. How to handle the reconnect to SFSB correctly? It seems that EJB sessions are gone after the WildFly is restarted. Should I recreate a proxy using an InitialContext or is there a better way, for example using a default EJB's Infinispan cache-container with file-store?

       

      Thanks in advance,

      Bartek

        • 1. Re: Reconnecting to @Stateful EJB
          Wolfgang Mayer Master

          Your statement made above is not correct "Reconnecting to SLSBs work fine". The SLSB may contain a state specific to that client only for the duration of the invocation. I think what you are looking for is an option to persist SFSBs. But as mentioned in the JavaEE tutorial "A session bean is not persistent. (That is, its data is not saved to a database.)". Since the EJBs are managed by the container they are also removed if the server is shut down. In the specification you may read: "If a client makes a call to a stateful session or entity object that has been removed, the container should throw the javax.ejb.NoSuchEJBException". A solution might be to store the state in your program before the bean is destroyed and restore the state when the bean is available again (@PostConstruct)

          • 2. Re: Reconnecting to @Stateful EJB
            Bartosz Piotrowski Newbie

            Thanks for the answer and proposed solution but I will probably convert the bean to SLSB because it is cheaper for us.