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

    EJB Accessing Local Entity Bean

    apavlo Newbie

      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>