Refresh injected EJB reference

Hello,

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?

My setup:

  • Vaadin 6.7.3
  • EJB 3.0
  • Java 6
  • Weblogic 10.3.6.0

Hello,

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);

Hope this helps.

Thanks,
Krishna

Thanks for you reply. Actually I’m not the one who designed the app, but I guess it’s using this article as a base:
https://vaadin.com/wiki/-/wiki/Main/Adding%20JPA%20to%20the%20Address%20Book%20Demo

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:

Hello,

My Apologies for the late reply,

I still think , you should do a look up to get an EJB, rather than passing it over to the application. Anyway, it is up to you to decide.

For you reference, Please follow this
link
& this
link
- for details. Hope this helps you

Thanks,
Krishna.

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.

Sorry, I didn’t see your reply before posting mine. Thanks for the links, they are definitely useful. I guess I will have to use JNDI.