• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to lookup Bean by JNDI name:javax.naming.NameNotFoundException: comp not bound

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I'm new to EJB world, though currently EJB 3.1 is the latest, I wanted to get my hands dirty with EJB 2.1 and slowly move upwards to 3.1, but I stumbled at my first program and could not greet the world :-)

Environment
Eclipse Juno,
JDK 1.5
J2EE 1.4
JBOSS 4.0


Below are my steps
1 ) I created an EJB Project called HelloWorld using eclipse associated that with an EAR project. Now I see two projects in workspace HelloWorld and HelloWorldEAR.
2 ) Created EJBHome, EJBObject and SessionBean
3 ) I have ejb-jar.xml and JBOSS.xml added to HelloWorld/ejbModule/META-INF as follows



After all the above steps, I right clicked the HelloWorldEAR and exported the project as ear and it created me an ear file which I deployed to C:\jboss-4.0.0\server\default\deploy\HelloWorldEAR.ear

and started the server. In JMX-Console I also confirm the deployment as I see


As the last step, I wrote a stand alone client as below to run



but getting exception as

Exception in thread "main" javax.naming.NameNotFoundException: comp not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:529)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:508)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at edu.learning.client.Client.lookUp(Client.java:35)
at edu.learning.client.Client.main(Client.java:23)


What is the mistake I'm doing and how to fix this ?

Thanks
Prakash
 
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prakash,
EJB 3 and EJB 2.1 both version of EJB do things differently so you can directly move to EJB 3.
The main thing is in EJB 3 you can use EJB component as simple POJO as well as EJB but in EJB 2.1 you cannot do such thing.
Also you can use annotations in EJB 3
 
Prakash Pantula
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ninad. But as I said, I wish to learn how EJB 2.1 works before appreciating later versions.

Could you please tell me where the mistake is?
 
Ninad Kulkarni
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using relative paths instead of absolute paths like "ejb/HelloWorld" while calling lookup method I hope this will help you
Refer this for EJB3
 
Prakash Pantula
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ninad,

Using Relative path like "HelloWorld" alone worked for me. But I still have this basic question, as per the Sun specifications, should we not actually give the absolute path, how does JNDI know, if HelloWorld is under ejb or env or some other context.

Also, I think, there is something fundamentally wrong I'm doing, but just not able to figure it out.

As an experiment, I tried to define like ENV in JNDI in my ejb-jar.xml like



My intention is to get MAX using JNDI, so I tried to lookup as



I get the exception

javax.naming.NameNotFoundException: comp not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
at org.jnp.server.NamingServer.lookup(NamingServer.java:253)



and then I tried something like ctx.bind("MAX",new Integer(100));
and then called ctx.lookUp("MAX") which did give me an Integer back.

So is binding not happening properly in the former case, when included in ejb-jar.xml or am I doing anything stupid ?

 
Prakash Pantula
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be too much of information provided in my original post is causing confusion, so I will try to keep my questions short and brief.


Assuming the original setup as posted in my original post, i.e I have only ejb-jar.xml (no vendor specific descriptor files like jboss.xml or for some other vendor) and I have <ejb-name>HelloWorld</ejb-name>

Question 1) - If I had to call the enterprise bean from a standalone client not deployed along with the enterprise beans in a container, do I look up the stub for home using lookup("HelloWorld") or lookup("java:comp/env/ejb/HelloWorld"). Because lookup("HelloWorld") seems to be working for me, when I try the other option, I get exceptions like comp not bound. Could this be because of "In the absence of a jboss.xml specification of the jndi-name for an EJB, the home interface is bound under the ejb-jar.xml ejb-name value" ?

Question 2) I did see examples in many posts flooded in internet, where they used the lookup against java:comp/env/ejb/HelloWorld and it seems to be working fine for them. Is that because, they used a different vendor not like JBoss 4.0 or, they would have looked up like this, from servlet or another component deployed on same jvm as that of enterprise beans as one single ear package.

Question 3) When I looked in JMX console, I noticed HellowWorld under Global JNDI namespace. Is that because, I did not vendor specific descriptor file like jboss.xml. If I had used Jboss.xml, do I need to specify like java:comp/env/ejb/HelloWorld specifically in ejb-jar.xml or jboss.xml. I have tried with different combinations and ended up with different exceptions.


Question 4) When do I use the lookup as

InitialContext iniCtx = new InitialContext();
Context ejbCtx = (Context) iniCtx.lookup("java:comp/env/ejb");
ShoppingCartHome home = (ShoppingCartHome) ejbCtx.lookup("ShoppingCartHome");

vs

InitialContext iniCtx = new InitialContext();
ShoppingCartHome home = (ShoppingCartHome) iniCtx.lookup("ShoppingCartHome");

Please help me understand this.

Thanks

 
reply
    Bookmark Topic Watch Topic
  • New Topic