Yet another NameNotFoundException

Im facing what seems to be a common problem with developers new to J2EE and I've been studying questions and answer posted in this forum, but hey, I still couldn't find the solution. So please help me if you can. I'm using the RI version 1.3.

I have simple application with a session and an entity bean. When deploying I get the following messages:

...

Binding name:`java:comp/env/ejb/SimpleCounter`

Binding name:`java:comp/env/ejb/SimpleCounterSession`

...

From my web tier (JSP+bean) I can access the session bean "SimpleCounterSession", but when I look for the entity bean "SimpleCounter" from the session bean using the code

...

javax.naming.Context jndiContext = new InitialContext();

Object objref = jndiContext.lookup("java:comp/env/ejb/SimpleCounter");

counterHome = (CounterHome)PortableRemoteObject.narrow(objref, CounterHome.class);

...

I get the following exception:

javax.naming.NameNotFoundException: SimpleCounter not found

<<no stack trace available>>

Does anybody have an idea on what I'm doing wrong?

Thanks,

Enrico

[1173 byte] By [gulfi] at [2007-9-26 12:30:55]
# 1
How do you get SimpleCounterSession? I am not familiar with the RI version, but do you need to specify the providerURL? That is standard as I know. If they are on the same machine, you use 'providerURL=localhost' in the property to create InitialContext.PC
pengjuc at 2007-7-2 3:15:36 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Look in the JNDI sections of the deployment. For the session bean the EJB Refs tab has ejb/SimpleCounter in the Coded name column, and then something below, in JNDI field (say, myCounter). Then, in application you have JNDI Names tab as well (it's also one of the screens you see it when you are ready to deploy). So, myCounter appears in Ref Type table for the Session bean, and you also need to add it in the last column for the entity bean.

Hope that helps

Felix

virshu at 2007-7-2 3:15:36 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Thanks Felix. I checked the EJB refs and JNDI names tabs settings but believe they are correct. Here is an extract of the sun-j2ee-ri.xml that I found in the counter.ear file:

<j2ee-ri-specific-information>

...

<web>

<module-name>war-ic.war</module-name>

<context-root>counter</context-root>

<ejb-ref>

<ejb-ref-name>ejb/SimpleCounterSession</ejb-ref-name>

<jndi-name>MyCounterSession</jndi-name>

</ejb-ref>

</web>

<enterprise-beans>

<module-name>ejb-jar-ic47.jar</module-name>

<unique-id>0</unique-id>

<ejb>

<ejb-name>CounterEJB</ejb-name>

<jndi-name>MyCounter</jndi-name>

</ejb>

...

</enterprise-beans>

<enterprise-beans>

<module-name>ejb-jar-ic4.jar</module-name>

<unique-id>0</unique-id>

<ejb>

<ejb-name>CounterSessionEJB</ejb-name>

<jndi-name>MyCounterSession</jndi-name>

....

<ejb-ref>

<ejb-ref-name>ejb/SimpleCounter</ejb-ref-name>

<jndi-name>MyCounter</jndi-name>

</ejb-ref>

</ejb>

</enterprise-beans>

</j2ee-ri-specific-information>

Again, I really don't see why the entry ejb/SimpleCounter does not seem to exist in the JNDI table... I'm running out of ideas...

Enrico

gulfi at 2007-7-2 3:15:36 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

> How do you get SimpleCounterSession? I am not familiar

> with the RI version, but do you need to specify the

> providerURL? That is standard as I know. If they are

> on the same machine, you use 'providerURL=localhost'

> in the property to create InitialContext.

> PC

Thanks PC. I'm not aware of any specific settings required for this purpose. At least this is what I read in the J2EE tutorial....

Enrico

gulfi at 2007-7-2 3:15:36 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

Here is a thought... The xml file refers to MyCounter; hoewever the exception refers to SimpleCounter. Look again at the JNDI tab for application. The values in the JNDI column of the upper table (Application) have to match JNDI column of the lower table (References). Do you see SimpleCounter (*not* ejb/SimpleCounter) anywhere?

Felix

virshu at 2007-7-2 3:15:36 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

Felix,

I checked again and didn't see any inconsistency. I have taken a screen shot of the JNDI tab that you can find on http://www.ticino.com/usr/gulfi/java/forte.jpg. Do you see anything abnormal?

FYI, I also rebuilt the entire application using Forte 4J CE V3.0 with the J2EE IDE. Same result, maybe not surprisingly. Moreover, I redeployed an app developed for J2EE V1.2.1 and deployed the Roster app that comes with the J2EE tutorial V1.3.

Both have session beans looking for entity beans and work perfectly! I'm clueless...

Enrico

gulfi at 2007-7-2 3:15:36 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7
You are right - nothing suspicious... Now, this message - javax.naming.NameNotFoundException: SimpleCounter not found still bothers me. Are you sure you don't have any lookups in your code for just SimpleCounter?
virshu at 2007-7-2 3:15:36 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8

Felix,

here is the CounterSessionEJB.ejbCreate method where things go wrong:

public String ejbCreate() throws CreateException {

try {

System.out.println ("lookup counter bean");

javax.naming.Context jndiContext = new InitialContext();

Object objref = jndiContext.lookup("java:comp/env/ejb/SimpleCounter");

counterHome = (CounterRemoteHome)PortableRemoteObject.narrow(objref, CounterRemoteHome.class);

} catch (Exception ex) {

ex.printStackTrace();

}

return null;

}

The exception occurs right after the message "lookup counter bean". If this entry does not exist in the JNDI table, what error message should I expect? Something like: "ejb/SimpleCounter not found"?

Enrico

gulfi at 2007-7-2 3:15:36 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9

Hi guys, I'm a software engineering student who's been working with some of the same problems. I was also getting a NameNotFoundException in my client. The problem occurred when I changed the lookup string in the client after noticing that it was the same as the code it had been copy/pasted from.

I recompiled the system, and went into deploytool to make sure that the JNDI names were now correct. They were, so I hit 'update and redeploy.' This was when i started getting the NameNotFoundException, with the old name! What's going on here?

I was able to 'fix' the problem by deleting the client jar by hand, updating the deploytool (it correctly detected the changes), then saying deploy. I explicitly stated where the client .jar should be.

This made the problem go away. I would expect that you've already tried this, since you've been working on it for a while. I just wanted to explain that i was seeing a similar problem where everything looked good in the deploytool, but the client .jar was not getting the updated code for some reason.

phil_light at 2007-7-2 3:15:36 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10
Phil,interesting enough, the NameNotFoundException is raised when the session bean looks for the entity bean. When my "client" (a JSP helper bean) looks for the session bean, everything works fine. I will try to deploy the same app on V1.2.1 and see what happens...Enrico
gulfi at 2007-7-2 3:15:36 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 11

This is what I call computer science... fiction! Just for fun I tryed to "lookup" the entity bean using its JNDI name "MyCounter". Suddendly I started getting a TransactionRolledbackException at a point where the entity bean had to exist. (BTW, why does this lookup not raise a NameNotFoundException?) So I decided to switch back to the original looup using "java:comp/env/ejb/SimpleCounter". To my surprise the only exception raised was the TransactionRolledbackException, and not the NameNotFoundException :-0

I found a bad formatted EJB-QL statement, fixed it and now everthing works perfectly!!!!!

As I said: computer science... fiction.

Enrico

gulfi at 2007-7-2 3:15:36 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...