0 Replies Latest reply on Mar 31, 2004 6:28 AM by steffen42

    JNDI access to local EJB interface

    steffen42 Newbie

      Hi!

      I'm trying to access a EntityBean from a servlet via the bean's local
      home interface. But I get a javax.naming.NameNotFoundException.
      The EJB and the Servlet are together in one .ear file
      and I'm using JBoss 3.2.3. I think the "<local-jndi-name>" in
      jboss-web.xml is wrong. But I don't know what to write there. I've
      searched for examples or other help, but I haven't found anything
      useful.

      Thanks for your help in advance!

      Steffen

      My XML files:

      --- jboss-web.xml ----------------------------------
      <jboss-web>
      <ejb-local-ref>
      <ejb-ref-name>ejb/Article</ejb-ref-name>
      <local-jndi-name>beans/ArticleLocalHome</local-jndi-name>
      </ejb-local-ref>
      </jboss-web>

      --- web.xml ----------------------------------
      <web-app>
      <display-name>Versionierung: newArticle</display-name>

      <servlet-name>newArticleServlet</servlet-name>
      <servlet-class>servlets.newArticleServlet</servlet-class>

      <servlet-mapping>
      <servlet-name>newArticleServlet</servlet-name>
      <url-pattern>/newArticle</url-pattern>
      </servlet-mapping>
      <ejb-local-ref>
      Local reference to ArticleBean
      <ejb-ref-name>ejb/Article</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      <local-home>beans.ArticleLocalHome</local-home>
      beans.ArticleLocal
      </ejb-local-ref>
      </web-app>

      --- ejb-jar.xml ----------------------------------
      <ejb-jar>
      <enterprise-beans>

      <display-name>Article CMP-Entity Bean</display-name>
      <ejb-name>ArticleEJB</ejb-name>
      beans.ArticleHome
      beans.Article
      <local-home>beans.ArticleLocalHome</local-home>
      beans.ArticleLocal
      <ejb-class>beans.ArticleBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Article</abstract-schema-name>
      <!--cmp-fields...-->
      <primkey-field>pk</primkey-field>

      <query-method>
      <method-name>findAll</method-name>
      <method-params/>
      </query-method>
      <ejb-ql>
      SELECT OBJECT(a) FROM Article AS a
      </ejb-ql>


      </enterprise-beans>
      <assembly-descriptor>
      <container-transaction>

      <ejb-name>ArticleEJB</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>

      --- servlet code ----------------------------------
      ...
      public void init(ServletConfig config) throws ServletException {
      super.init(config);
      try {
      InitialContext jndiContext = new InitialContext();
      articleHome =
      (ArticleLocalHome)jndiContext.lookup("java:comp/env/ejb/Article");
      }
      catch (NamingException e) {
      System.out.println("JNDI lookup error!");
      throw new ServletException(e);
      }
      }
      ...