aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Exception while doing lookup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Exception while doing lookup" Watch "Exception while doing lookup" New topic
Author

Exception while doing lookup

Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Hello sir, madam, friends

I am getting NameNotFoundException when I do a look up.
Context c = new InitialContext();
Object o = c.lookup("Local"); // 2

I get the exception at line 2. I am wondering why I get this exception when I use EJBLocalHome and EJBLocalObject i.e while dealing with local clients. I dont get this exception when I using EJBObject and EJBHome classes i.e with remote clients. As far my understanding goes the lookup process is the same whether we are dealing with local or remote clients.I am using Reference Implementation server provided by Sun.
I am trying to run different applications. One application is where I am using remote clients ad other application is where I am using local clients. When I run my remote client I dont see any NamingException. But when I run my local client then I get NameNotFoundException.Both the applications are nowhere related to each other.I verfied the JNDI name that I provided while deployment to the one the client is doing lookup on. Both the names are matching.

Can anyone please help me out where I am going wrong ?

Waiting for your replies

~Rohit.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2861
    
  11

Yes, the process of looking up regular (remote) Home intefaces and Local Home interfaces is the same, with the exception that the remote version should be "narrowed" using the PortableRemoteObject class before it is used. The JNDI name for local and remote homes must be different though, so I don't understand your claim that they are the same. They are separate objects, so they must be bound in JNDI under different names.

The bottom line is "Local" does not exist in your JNDI tree. Focus your efforts on figuring out why not.
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Originally posted by Greg Charles:
Yes, the process of looking up regular (remote) Home intefaces and Local Home interfaces is the same, with the exception that the remote version should be "narrowed" using the PortableRemoteObject class before it is used. The JNDI name for local and remote homes must be different though, so I don't understand your claim that they are the same. They are separate objects, so they must be bound in JNDI under different names.

The bottom line is "Local" does not exist in your JNDI tree. Focus your efforts on figuring out why not.


Thanks Greg.. I will try changing the JNDI name and will check.
Thanks for the reply.

~Rohit.
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Hello friends, sir, madam

I ensured that the JNDI name and the lookup name are the same. Also right now I have only one application deployed in Sun's RI server. I am still getting the exception NameNotFoundException. Dont know why I am getting the exception. Can anyone please help me out?

Waiting for your reply.

Thanks and Regards
Rohit.
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Hello all,
Just want to conform , in one of the forum I read that the client program should run within the same JVM as that of EJB in case you are implementing local clients.
Uptill now I was doing the following steps
1. Deploy EJB using local interface in RI
2. Launch a new cmd prompt and run the client program which in my case was a standalone program with a main method

So this will create a new instance of JVM and will run my program. That means this is a different instance of JVM as compared to one in which my J2EE RI server is running. So does this cause a problem for lookup as I am still getting NameNotFoundException.

Please correct me if I am wrong.
Waiting for your replies.


Thanks and Regards
Rohit.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Local interface lookup will work only within the same JVM and and when the client is in the same application.


Groovy
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Originally posted by Pradip Bhat:
Local interface lookup will work only within the same JVM and and when the client is in the same application.


Thanks Pradip for the reply. But I have tried that too. I have created a remote session bean and in that I have written a business method which invokes the local EJB. i.e this business method contains the jndi lookup code for the local bean. But still I am not able to find the jndi name. I am using Reference Implementation server from Sun.

Can you please help me why I am not able to find the jndi name. I have made necessary checks whether I provide the same name that I gave at deploytime etc.

Waiting for your reply.

~Rohit
Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
When accessing an EJB from another EJB, a reference JNDI (defined in deployment descriptor) should be used instead of global JNDI.
I use webshpere, and to find a local EJB from the same JVM ( a JSP in the same JVM), I prefixed the LOCAL EJB JNDI with "local:ejb/", and it worked.
I figured out this by running a batch file named 'dumpnamespace.bat' in websphere installation.
check if there is any similar batch file in the appserver folders and use it to see the current deployed JNDI objects
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Hello Reddy sir,

Well in one of the forum, I got a reply about how to print the JNDI tree. And I noticed that the name I was using for registering the Local EJB is not getting printed in my program. i.e somehow the name is not getting registered. Can you please have a look at the following link in which the person has given how to print the JNDI tree.
http://www.theserverside.com/discussions/thread.tss?thread_id=39614

Thanks and Regards
Rohit.
Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
Hello friends

I forgot to mention the ejb-ref parameter while using local interface thats why my jndi name for local client was not getting registered using Sun' Reference Implementation server

I just made a note that
a. I made entry for ejb-ref parameter using RI's deploytool.
b. Ensured that my client and my EJB are working in the same JVM.

By taking care of the above points, I am able to invoke methods on my ejb that is implementing local interface.

Thanks and Regards
Rohit.
Srinivasan Rengan
Ranch Hand

Joined: Nov 07, 2004
Posts: 122
Hi Rohit,
Can you please help me to do the reference for the local home and component. Also, how should the business method, which takes the reference of the local home from the JNDI, look like? In my case, I have already registered my remote using the name "MyJndi". Now, how should i make the invocation for the local home into my business method?

Thanks in advance!
Srini
[ April 02, 2006: Message edited by: Srinivasan R ]

SCJP, SCWCD, SCBCD (EJB 2.x and EJB 3), OCA, SCDJWS
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception while doing lookup