File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes EJB 3.0 local lookup fails with OC4J & JDK 1.5.x Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 3.0 local lookup fails with OC4J & JDK 1.5.x" Watch "EJB 3.0 local lookup fails with OC4J & JDK 1.5.x" New topic
Author

EJB 3.0 local lookup fails with OC4J & JDK 1.5.x

Mahesh Kakade
Greenhorn

Joined: Nov 24, 2005
Posts: 8
1) Local Interface


2) Remote Interface


3) EJB


4) Registring a reference to CircuitServiceSLSB EJB under the logical name CircuitServicesRef
In the ReportingServiceSlsb EJB, I am trying to lookup the local ejb interface CircuitServiceLocal.



Here in the createReport() method the lookup fails throwing the NameNotFoundException. (try catch is there in the code but not shown.)
In createReport() method I want the reference of the CircuitService EJB (local).

Exception:
javax.naming.NameNotFoundException: java:comp/env/CircuitServicesRef not found in ReportingServiceSlsb

Can anybody explain what is going wrong here.
I am using OC4J 10.1.3.4.0 and JDK 1.5.0_16

I know here I can inject the ejb using @EJB annotation, (and that works fine in my code) but for different reason, I have to use the JNDI lookup method.

One more thing is that I am using the lookup method to lookup the remote interface by passing the ejb name CircuitServiceSLSB, it is working fine.

the remote Lookup


Thanks & Regards,
Mahesh
Mahesh Kakade
Greenhorn

Joined: Nov 24, 2005
Posts: 8
Hello All!

Can anybody please explain me why the JNDI lookup method is not able to find the the local interface reference which is defined through annotation in another ebj?
Any help would be appreciated.

Thnx & Rgds,
Mahesh
Dan Kempten
Greenhorn

Joined: Dec 26, 2008
Posts: 25
One thing is obvious.
In one part of your code you put @EJB above class xyz.

I've been working with this for a couple weeks and this is not how I use the EJB annotation.

You should put the @EJB above an instance variable that represents the Bean you wish to inject.
And keep it inside the class.

I use it in a web app or a client app to replace this code :

with this code :



Stu Quinn
Ranch Hand

Joined: Feb 27, 2009
Posts: 35
I have not use OC4J, but if you still have any issues take a close look at the server log to ensure your project was deploying, then I would take a look at the JNDI browser.

Good luck,
Stu
Mahesh Kakade
Greenhorn

Joined: Nov 24, 2005
Posts: 8
Dan Kempten wrote:
You should put the @EJB above an instance variable that represents the Bean you wish to inject.
And keep it inside the class.


As I already explained above, that I don't want to inject the ejb. (For there is no way to inject the ejb conditionally.)
That's why I am using the JNDI lookup.

Dan Kempten wrote:
I use it in a web app or a client app to replace this code :



Does your above code works? Where did you define the JNDI name "MyJNDINameOfMyBean"?
Or did you replace the above code b'coz it was not working?

Dan Kempten wrote:
with this code :



By this you are actually injecting the bean, which I don't want to.
If this optional element "mappedName" is not defined, still the ejb does gets injected.
Is there any specific reason for defining this element?

Finally I want to get the ejb reference through JNDI lookup and not by DI.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10113
    
165

Mahesh,

Your @EJB usage on the EJB class looks correct. The only reason i can think of it not working is if the createReport() method gets called before the @EJB reference is made available in the ENC. When is the createReport() method being called? Does it get called in the constructor of the bean or is it a business method which the client of the bean calls? If it's the latter, please post the client code where you are calling the method.

[My Blog] [JavaRanch Journal]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10113
    
165

And you might also want to check if this is some known bug with the version of OC4J server you are using.
Mahesh Kakade
Greenhorn

Joined: Nov 24, 2005
Posts: 8
Here is the client code calling the createReport() method...



Is anything going wrong here?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB 3.0 local lookup fails with OC4J & JDK 1.5.x