0
votes

i am developping a maven enterprise application using netbeans, glassfish3.1, EJB3 and JSF2. I want to inject a DAOFacade EJB into a JSF managed bean but it does'nt work. here is the error message:

Caused by: javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=com.procc.beans.AlertController/ejbFacade,Remote 3.x interface =com.procc.dao.AlertFacade,ejb-link=null,lookup=,mappedName=,jndi-name=com.procc.dao.AlertFacade,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'com.procc.dao.AlertFacade#com.procc.dao.AlertFacade' [Root exception is javax.naming.NamingException: Lookup failed for 'com.procc.dao.AlertFacade#com.procc.dao.AlertFacade' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: com.procc.dao.AlertFacade#com.procc.dao.AlertFacade not found]]

DAOFacade is located into the EJB module and the JSF managed bean into the war module.

+EAR-project

--+EJB-module

------AlertFacade.java

--+WAR-module

------AlertController.java

I tried to inject the same EJB into a servlet and it went just fine, like this:

@WebServlet(name = "DAOServlet", urlPatterns = {"/DAOServlet"})
public class DAOServlet extends HttpServlet {

  @EJB
  private AlertFacadeLocal alertFacade;
  @EJB
  private AnomalyFacadeLocal anomalyFacade;

  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
      List alertList = alertFacade.findAll();
      out.println("found "+alertList.size()+" alerts");
  }   
}    

here is the JSF Managed bean : @ManagedBean @ViewScoped public class AlertController extends AbstractController implements Serializable {

  @EJB
  private AlertFacade ejbFacade;

  public AlertController() {
      super(Alert.class);
  }

  @PostConstruct
  public void init() {
      super.setFacade(ejbFacade);
  }

}

and this is the DAO facade EJB:

@Stateless
public class AlertFacade extends AbstractFacade<Alert> implements AlertFacadeLocal {
  @PersistenceContext(unitName = "flams_pu")
  private EntityManager em;

  @Override
  protected EntityManager getEntityManager() {
      return em;
  }

  public AlertFacade() {
      super(Alert.class);
  }    
}

I searched the internet but i could'nt resolve the problem. Please help.

yes, wright! i forgot about controller managed bean. Here it is:

@ManagedBean
@ViewScoped
public class AlertController extends AbstractController<Alert> implements Serializable {

@EJB
private AlertFacade ejbFacade;

public AlertController() {
    super(Alert.class);
}

@PostConstruct
public void init() {
    super.setFacade(ejbFacade);
}   

}

In JSF page:

<p:dataTable var="item" value="#{alertController.items}" paginator="true">

The error is thrown by the injection of ejbFacade into AlertController.

1
Write detailed code of managed bean and session beanJitesh

1 Answers

0
votes

I faced a similar problem and I didn't manage to resolve it, despite of some blogs claim that is possible, see this link. I haven't tried but I suppose that is only possible in a web application (war packaging) not in an enterprise application (ear packaging).

Finally I decided to use CDI as bean manager and injection provider. see these tutorials: