Problem calling a session bean (EJB 3.0)


EJB programming & troubleshooting: Problem calling a session bean (EJB 3.0)

  1. Problem calling a session bean (EJB 3.0) (2 messages)

    Hello, I'm new to netbeans and J2EE. I'm using NetBeans 5.5 Beta 2 and sun application server 9 pe. I created a new enterprise application and i'm trying to access a Session Bean (Remote and Stateless) from the app-client (outside the main class). This is the loockup method that was generated by the IDE (Enterprise Resources > Call enterprise bean): private ejb.SessionBeanDoenteRemote lookupSessionBeanDoenteBean() { try { javax.naming.Context c = new javax.naming.InitialContext(); return (ejb.SessionBeanDoenteRemote) c.lookup("java:comp/env/ejb/SessionBeanDoenteBean"); } catch(javax.naming.NamingException ne) { java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne); throw new RuntimeException(ne); } } When I run the application and try to invoke the lookup method my application gets the following exception: SEVERE: exception caught javax.naming.NameNotFoundException: No object bound to name java:comp/env/ejb/Se ssionBeanDoenteBean at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl. java:751) at ava:156) at com.sun.enterprise.naming.SerialContext.lookup( ) at javax.naming.InitialContext.lookup( at intensivecare.entrada.JDialogEntrada.lookupSessionBeanDoenteBean(JDia at intensivecare.entrada.JDialogEntrada.buttonMenuGravarActionPerformed( at intensivecare.JDialogWizzard$2.jButtonGravarActionPerformed(JDialogWi at componentes.JTaskPanelMenu$3.actionPerformed( at javax.swing.AbstractButton.fireActionPerformed( 49) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav a:2169) ... Please... can someone help me?
  2. "java:comp/env" refers to component environment within the server.when you lookup from a remote client, you need to specify the naming prover url and namingcontext factory class in file or can pass as Properies object in new InitialContext(); Now when you try to lookup "java:comp/env/ejb/SessionBeanDoenteBean" you will get NameNotFoundException because the remote name which is bound is "SessionBeanDoenteBean" and not "java:comp/env/ejb/SessionBeanDoenteBean".So first see what are the objects bound in naming service and then you look up. Now you could have looked up if you were looking up one bean from another and you have defined the ejb-ref to something like ejb/SessionBeanDoenteBean. So keep in mind that "java:comp/env/" is incontainer stuff. cheers,
  3. This is getting frustrating![ Go to top ]

    Could someone please elaborate on this. I'm getting the same error and can't find any documentation on it. I'm trying to call an Stateless session bean (which manages an entity bean) through the Remote class in an application client, but, of course, this doesn't work. I've created an ejb jar file consisting of a set of entity classes. I've copied the jar into the client application's library. Now, I just want the Stateless session bean to return a message through the remote interface. Therefore, I've imported the remote interface of the Stateless session bean into the application client. So, how do I create an instance of the Stateless session bean (which manages the entity bean)? Here's the error: ----------------- javax.naming.NameNotFoundException: No object bound to name java:comp/env/ejb/UsersFacade Here's the lookup code: ----------------------- package worklogclient; import controller.UsersFacadeRemote; import java.util.logging.Level; import java.util.logging.Logger; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; public class WorkLogClient { UsersFacadeRemote uf; /** Creates a new instance of WorkLogClient */ public WorkLogClient() { System.out.print("Testing!"); uf = lookupUsersFacade(); } private UsersFacadeRemote lookupUsersFacade() { try { Context c = new InitialContext(); return (UsersFacadeRemote) c.lookup("java:comp/env/ejb/UsersFacade"); } catch(NamingException ne) { Logger.getLogger(getClass().getName()).log(Level.SEVERE,"exception caught" ,ne); throw new RuntimeException(ne); } } }