Servlet receives null from Remote EJB3 Session Bean

Posted by Hank on Stack Overflow See other posts from Stack Overflow or by Hank
Published on 2010-04-20T14:12:06Z Indexed on 2010/04/20 14:13 UTC
Read the original article Hit count: 514

I'm sure this is a beginner error...

So I have a JEE6 application with entities, facades (implementing the persistence layer) and Stateless Session Beans (EJB3) with Remote interfaces (providing access to the entities via facades).

This is working fine. Via the SLSB I can retrieve and manipulate entities.

Now, I'm trying to do this from a Web Application (deployed on the same Glassfish, entity+interface definitions from JEE app imported as separate jar). I have a Servlet, that receives an instance of the SLSB injected. I get it to retrieve an entity, and the following happens (I can see it in the logs):

  • the remote SLSB gets instantiated, its method called
  • SLSB instantiates the facade, calls the 'get' method
  • facade retrieves object from DB, returns it
  • SLSB returns the object to the caller
    • (all is good until here)
  • calling servlet receives .. null !!

What is going wrong? This should work, right?

MyServlet:

public class MyServlet extends HttpServlet {

  @EJB
  private CampaignControllerRemote campaignController; // remote SLSB

  protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();
    try {
      Campaign c = campaignController.getCampaign(5L); // id of an existing campaign
      out.println("Got "+ c.getId()); // c is null !!
    } finally { 
        out.close();
    }
  }
  ...
}

Pls let me know if you want to see other code, and I'll update the post.

© Stack Overflow or respective owner

Related posts about ejb3

Related posts about jee6