By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,117 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,117 IT Pros & Developers. It's quick & easy.

JNDI access to local EJB interface

P: n/a
Hi!

I'm trying to access a EntityBean from a servlet via the bean's local
home interface. 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>
<servlet-name>newArticleServlet</servlet-name>
<servlet-class>servlets.newArticleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>newArticleServlet</servlet-name>
<url-pattern>/newArticle</url-pattern>
</servlet-mapping>
<ejb-local-ref>
<description>Local reference to ArticleBean</description>
<ejb-ref-name>ejb/Article</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>beans.ArticleLocalHome</local-home>
<local>beans.ArticleLocal</local>
</ejb-local-ref>
</web-app>

ejb-jar.xml:
<ejb-jar>
<enterprise-beans>
<entity>
<display-name>Article CMP-Entity Bean</display-name>
<ejb-name>ArticleEJB</ejb-name>
<home>beans.ArticleHome</home>
<remote>beans.Article</remote>
<local-home>beans.ArticleLocalHome</local-home>
<local>beans.ArticleLocal</local>
<ejb-class>beans.ArticleBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Long</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Article</abstract-schema-name>
<!--cmp-fields...-->
<primkey-field>pk</primkey-field>
<query>
<query-method>
<method-name>findAll</method-name>
<method-params/>
</query-method>
<ejb-ql>
SELECT OBJECT(a) FROM Article AS a
</ejb-ql>
</query>
</entity>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>ArticleEJB</ejb-name>
<method-name>*</method-name>
</method>
<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);
}
}
....
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.