It's not a secret anymore!*
The moose likes EJB and other Java EE Technologies and the fly likes cmp 2.x jndi local lookup fails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "cmp 2.x jndi local lookup fails" Watch "cmp 2.x jndi local lookup fails" New topic
Author

cmp 2.x jndi local lookup fails

Philip Rowley
Greenhorn

Joined: Jul 18, 2007
Posts: 4
Hi, I seem to of been on this problem for weeks.

Trying to find a Stock CMP Entity beans local interface from a session bean.

Using Rational Application Developer 7, from the Universal Test Client I can find the StockCMPLocalHome interface. However with the following jndi code variations from the session bean I cannot find it.

-BEGIN CODE----------------------------
try {
jndiname = "java:comp/env/ejb/Stock";
o = context.lookup(jndiname);
} catch (NamingException ne1) {
System.out.println("ONE FAILED "+jndiname+" Err="+ne1.getMessage());
}

try {
jndiname = "java:comp/env/ejb/StockCMPLocal";
o = context.lookup(jndiname);
} catch (NamingException ne1) {
System.out.println("TWO FAILED "+jndiname+" Err="+ne1.getMessage());
}

try {
jndiname = "java:comp/env/Stock";
o = context.lookup(jndiname);
} catch (NamingException ne1) {
System.out.println("THREE FAILED "+jndiname+" Err="+ne1.getMessage());
}


try {
jndiname = "java:comp/env/ejb/StockCMP";
o = context.lookup(jndiname);
} catch (NamingException ne1) {
System.out.println("FOUR FAILED "+jndiname+" Err="+ne1.getMessage());
}

try {
jndiname = "java:comp/env/ejbs.StockCMPLocalHome";
o = context.lookup(jndiname);
} catch (NamingException ne1) {
System.out.println("FIVE FAILED "+jndiname+" Err="+ne1.getMessage());
}

try {
jndiname = "java:comp/env/ejbs.StockCMP";
o = context.lookup(jndiname);
} catch (NamingException ne1) {
System.out.println("SIX FAILED "+jndiname+" Err="+ne1.getMessage());
}
-END CODE----------------------------

I have provided the output below, note it cannot even find the ejb namespace in some.

-BEGIN ERR----------------------------
[18/07/07 21:13:45:781 CEST] 00000023 SystemOut O ONE FAILED java:comp/env/ejb/Stock Err=Name comp/env/ejb not found in context "java:".
[18/07/07 21:13:45:781 CEST] 00000023 SystemOut O TWO FAILED java:comp/env/ejb/StockCMPLocal Err=Name comp/env/ejb not found in context "java:".
[18/07/07 21:13:45:781 CEST] 00000023 SystemOut O THREE FAILED java:comp/env/Stock Err=Name "comp/env/Stock" not found in context "java:".
[18/07/07 21:13:45:781 CEST] 00000023 SystemOut O FOUR FAILED java:comp/env/ejb/StockCMP Err=Name comp/env/ejb not found in context "java:".
[18/07/07 21:13:45:781 CEST] 00000023 SystemOut O FIVE FAILED java:comp/env/ejbs.StockCMPLocalHome Err=Name "comp/env/ejbs.StockCMPLocalHome" not found in context "java:".
[18/07/07 21:13:45:781 CEST] 00000023 SystemOut O SIX FAILED java:comp/env/ejbs.StockCMP Err=Name "comp/env/ejbs.StockCMP" not found in context "java:".
-END ERR----------------------------

I have also included the ejb-jar.xml file below.

-BEGIN ejb-jar.xml------------------
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
<display-name>
StockEJB</display-name>
<enterprise-beans>
<entity id="StockCMP">
<ejb-name>StockCMP</ejb-name>
<local-home>ejbs.StockCMPLocalHome</local-home>
<local>ejbs.StockCMPLocal</local>
<ejb-class>ejbs.StockCMPBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>false</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>StockCMP</abstract-schema-name>
<cmp-field id="CMPAttribute_1184702097046">
<field-name>id</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1184702097047">
<field-name>sname</field-name>
</cmp-field>
<primkey-field>id</primkey-field>
</entity>
<session id="StockList">
<ejb-name>StockList</ejb-name>
<home>ejbs.StockListHome</home>
<remote>ejbs.StockList</remote>
<ejb-class>ejbs.StockListBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>

-END ejb-jar.xml--------------------

Thanks Phil
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
The JNDI name is specified in the <ejb-local-ref> element in the entity bean EJB deployment descriptor. It should look like this:


You should now be able to do a JNDI look up using "java:comp/env/ejb/StockCMPBean".


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Philip Rowley
Greenhorn

Joined: Jul 18, 2007
Posts: 4
Hi

I tried to implement your xml but still cannot find namespace ejb. I also noticed you referenced the StockList session bean instead of the Stock entity bean in <local-home> and <local>.

I tried with your xml which referenced the entity and session bean. This failed with java:comp/env/ejb/StockCMPBean Err=Name comp/env/ejb not found in context "java:".

-BEGIN--------

JNDI Call Used = "java:comp/env/ejb/StockCMPBean";
Error Msg = java:comp/env/ejb/StockCMPBean Err=Name comp/env/ejb not found in context "java:".

<entity id="StockCMP">
<ejb-name>StockCMP</ejb-name>
<local-home>ejbs.StockCMPLocalHome</local-home>
<local>ejbs.StockCMPLocal</local>
<ejb-class>ejbs.StockCMPBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>false</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>StockCMP</abstract-schema-name>
<cmp-field id="CMPAttribute_1184702097046">
<field-name>id</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1184702097047">
<field-name>sname</field-name>
</cmp-field>
<primkey-field>id</primkey-field>
<ejb-local-ref>
<ejb-ref-name>ejb/StockCMPBean</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>ejbs.StockListHome</local-home>
<local>ejbs.StockList</local>
</ejb-local-ref>
</entity>
-END------------

I then tried with it modified to only reference the Stock entity bean, which also failed with the same error msg.

-BEGIN----------

JNDI Call Used = "java:comp/env/ejb/StockCMPBean";
Error Msg = java:comp/env/ejb/StockCMPBean Err=Name comp/env/ejb not found in context "java:".

<entity id="StockCMP">
<ejb-name>StockCMP</ejb-name>
<local-home>ejbs.StockCMPLocalHome</local-home>
<local>ejbs.StockCMPLocal</local>
<ejb-class>ejbs.StockCMPBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>false</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>StockCMP</abstract-schema-name>
<cmp-field id="CMPAttribute_1184702097046">
<field-name>id</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_1184702097047">
<field-name>sname</field-name>
</cmp-field>
<primkey-field>id</primkey-field>
<ejb-local-ref>
<ejb-ref-name>ejb/StockCMPBean</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<local-home>ejbs.StockCMPLocalHome</local-home>
<local>ejbs.StockCMPLocal</local>
</ejb-local-ref>
</entity>
-END--------

Looking at the error msg, it seems to me that it cannot get past the EJB namespace see msg again below

java:comp/env/ejb/StockCMPBean Err=Name comp/env/ejb not found in context "java:".


Thanks

Phil
Philip Rowley
Greenhorn

Joined: Jul 18, 2007
Posts: 4
When calling a local lookup from a Session or Entity bean, and it's looking for its self it works.

But when calling a local lookup from Session or Entity bean, and it's looking for a different Entity or Session bean it fails.

However, when I create a refence from an entity bean to a sessoin bean etc.. it works (thanks Roger).

ie using <ejb-local-ref> tag.

Why does this exist? It seems like an overhead with no real use? Can anyone suggest some reading, I have not come across this in my books, or understood it when I have read it.

Any reply welcome.

Thanks Phil
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cmp 2.x jndi local lookup fails
 
Similar Threads
InitialContext
JBOSS EntityBean CMP with MySQL Help
Local Home JNDI Lookup Failure
problems with JNDI name lookup
NameNotFoundException and jndi