0 Replies Latest reply on Aug 13, 2006 11:31 PM by Brian Bernstein

    trouble obtaining EJB reference in portlet

    Brian Bernstein Newbie

      I'm having trouble obtaining a reference to an EJB entity bean in a portlet.

      The entity bean has successfully deployed and I've confirmed the JNDI name in the jmx-console (PersonBean).

      I had first tried to obtain the reference through the EJB annotation, injecting it into the portlet as such:

      public class ModifyPerson extends GenericPortlet {
      @EJB(name="PersonBean")
      private PersonLocal bean;
      .
      .
      .
      }
      

      (PersonLocal is the local interface)

      However, this did not appear to work as I got a NullPointerException when I tried to call any of its methods.

      When that faied, I tried to do a JNDI lookup in the init() method:
      public void inti() throws PortletException{
       try{
       InitialContext ctx = new InitialContext();
       bean = (PersonLocal) ctx.lookup("java:/env/comp/PersonBean");
       }catch(NamingException ex){
       throw new PortletException(ex.getMessage());
       }
      }
      


      The portlet instance did not appear to have thrown any exceptions when initializing, which I had thought was promising, but when I try to call any of the bean's methods, I still get the NullPointerException.

      I am assuming this NullPointerException is the result of bean remaining as a null value as an actual reference to the bean is not obtained.

      Any help in this matter will be greatly appreciated.