1 Reply Latest reply on May 24, 2003 7:16 AM by haraldgliebe

    EJB Accessing Local Entity Bean

    apavlo

      I have a session bean and I want it to access a local entity bean. I'm not sure what I'm doing wrong, but I keep getting the error below. I'm not going to print out the whole stack because I know nobody reads them (I never do). I've read some tutorials, posts here and there I've followed just about every example and nothing works.

      ERROR [STDERR] javax.naming.NameNotFoundException: UserHome not bound
      ---------------------------------------------------------------
      Code that fails:
      try {
      InitialContext ctx = new InitialContext();
      Object ref = ctx.lookup( "java:comp/env/UserHome" );
      userBean = (UserHome)PortableRemoteObject.narrow( ref, UserHome.class );
      } catch (Exception NamingException) {
      NamingException.printStackTrace();
      ret += "Failed to find the local object!\n";
      }
      ---------------------------------------------------------------
      Sample from ejb-jar.xml

      <display-name>User Entity Bean</display-name>
      <ejb-name>UserEJB</ejb-name>

      com.auctioninc.UserHome
      com.auctioninc.User
      <ejb-class>com.auctioninc.UserBean</ejb-class>
      <ejb-link>User</ejb-link>

      <ejb-local-ref>
      <ejb-ref-name>UserHome</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      <local-home>com.auctioninc.UserLocalHome</local-home>
      com.auctioninc.User
      <ejb-link>User</ejb-link>
      </ejb-local-ref>

      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>user</abstract-schema-name>

      <cmp-field><field-name>id</field-name></cmp-field>
      <cmp-field><field-name>userName</field-name></cmp-field>
      <cmp-field><field-name>userCode</field-name></cmp-field>
      <cmp-field><field-name>FName</field-name></cmp-field>
      <cmp-field><field-name>LName</field-name></cmp-field>
      <cmp-field><field-name>email</field-name></cmp-field>

      <primkey-field>id</primkey-field>

      ---------------------------------------------------------------
      Sample from jboss.xml

      <ejb-name>UserEJB</ejb-name>
      <jndi-name>UserBean</jndi-name>
      <local-jndi-name>UserHome</local-jndi-name>

        • 1. Re: EJB Accessing Local Entity Bean
          haraldgliebe

          You need to declare the ejb-local-ref inside the session bean declaration, the ejb-link-name must match the ejb-name of the corresponding bean (in your case UserEJB, not User).
          You can always use the JNDIView MBean in the jmx-console to see what is bound in JNDI.

          Regards,
          Harald