I’m pretty new with Vaadin so excuse me if my questions are silly.
Here is my scenario: I’m working with Vaadin 6 on an app which uses a servlet that extends AbstractApplicationServlet. A few EJBs (stateless and stateful) are injected in it, at getter level. Those EJBs are then passed as parameter to the main application so that they can be used elsewhere.
Now and then, those EJBs throw a runtime exception (SQLException, for instance, in case of a DB timeout). According to the EJB spec, after the rollback of the transaction, the container will discard the EJB, letting it be collected by the garbage collector, and then throw an EJBException.
The problem, and I’m not sure if Vaadin is responsible or not, is that when I want to use this EJB again, after having dealt with the error, I get a ‘NoSuchEJBExeception: Bean has been deleted’. Which makes sense in a way as it has been discarded! But how can I get a fresh reference to this stateful bean? Is it the Vaadin container that holds a wrong reference? Is there a way to restart the servlet or the application in order to refresh the dependency injection?
I think you are mixing up things instead of passing the EJB to application class, Why can’t you get the instance of the EJB in the Application or in subsidary classes directly using InitialContext?
Say like you want to save the form data in to DB, once Save action has been performed, populate a POJO with a data, pass this to a Helper class. In the helper class do a look up for that EJB and perform the save action.
InitialContext context = new InitialContext(env);
YOUR_EJB_CLASS obj = (YOUR_EJB_CLASS)context.lookup(JNDI_NAME_OF_EJB_CLASS);
obj.save(POJO);
As for why EJBs are injected into the servlet, I guess from my readings that’s because it’s the only place where they can be injected (Weblogic’s servlet container).
I could use JNDI lookup, but there are two major problems with this approach:
the app is not designed that way, lots of code would be rewritten,
After doing some experimentations and researches, I guess that my most important question now is: is there a way to restart programmatically the subclass of AbstractApplicationServlet? I guess it’s the only way to retrieve a new reference to my stateful EJB, as even a restart of the application doesn’t seem to work.