Problem to call EJB from Servlet

Hi everybody,

Below is my problem:

I'm using Borland Enterprise Server AppServer Edition 5.2.1 and trying to call ejb object (ClientManager - Stateless Bean) from the servlet. This is how i'm doing it:

private ClientManagerHome clManagerHome;

Context ctx = new InitialContext();
           
clManagerHome = (ClientManagerHome)ctx.lookup("ClientManagerHome");

ClientManager clManager = clManagerHome.create();

and i'm getting the following error:

javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]

then i tried another way to call ejb:

private ClientManagerHome clManagerHome;

Context ctx = new InitialContext();

Object obj = ctx.lookup("ClientManager");
           
clManagerHome =  (ClientManagerHome)PortableRemoteObject.narrow(obj, ClientManagerHome.class);

ClientManager clManager = clManagerHome.create();

and i got the following error:

java.lang.ClassCastException: Cannot narrow without a stub class: secommerce._ClientManagerHome_Stub

i have checked this file _ClientManagerHome_Stub and it's there.

Does anyone know what's wrong and how to solve my problem??

Thq in advance.



LVL 1
worldsergaAsked:
Who is Participating?
 
PAQ_ManCommented:
Question Closed, 250 points refunded.
PAQ_Man
Community Support Moderator
0
 
suprapto45Commented:
Hi,

>>"javax.naming.NameNotFoundException"

Are you sure that you have bind your Stateless Bean into ClientManagerHome. It is normally configured in .xml file.

clManagerHome = (ClientManagerHome)ctx.lookup("ClientManagerHome");

Regards
Dave
0
 
suprapto45Commented:
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
patbinCommented:

try this one  


 InitialContext initContext = null;
initContext = new javax.naming.InitialContext();
     
   String JNDIName = "java:comp/env/ejb/ClientManager";
     
                  Object objref = initContext.lookup(JNDIName);

clManagerHome = (ClientManagerHome)PortableRemoteObject.narrow(objref,
ClientManagerHome.class);

ClientManager clManager=  clManagerHome.create();

hope this will solve ur problem    
0
 
worldsergaAuthor Commented:
Hi guys,

Thanks for the quick response.

patbin thanks but i did try it ("java:comp/env/ejb/ClientManager") before. It didn't help.

suprapto45 thanks but your link didn't help me.

I think something wrong with the AppServer. Somehow EJB 2.0 doesn't want to work on this server, i'm not sure why. I just tested EJB 1.1 and it is working fine.

Anyway thanks guys.
0
 
aozarovCommented:
Do you use ant to generate the jar?
I am not familure with Borland app server but you might need to include in the jar generated stubs (from your ejb) by applying some sort
of ejbc (ejb compiler) utility.
0
 
aozarovCommented:
Also, once you call with ClientManagerHome and once you call with ClientManager (which one the ejb home is bound)
You can probably list your jndi tree to validate it (also see what is the value in the borland specific ejb xml file related to jndi).
Also Did you try:
Context ctx = new InitialContext();
clManagerHome = (ClientManagerHome)ctx.lookup("ClientManager"); // as the other method seemd to find it
ClientManager clManager = clManagerHome.create();


0
 
worldsergaAuthor Commented:
Hi aozarov,

I have actually resolved all my problems.

Thanks.
0
 
worldsergaAuthor Commented:
Sorry guys,

Regarding the points. I don't really think that i should award anybody because eventually i have resolved my problem myself.

Any objections from you??

0
 
worldsergaAuthor Commented:
It's me again.

Guys i want to close this question and i would like to explain what was the problem. As I already mentioned the problem was with my AppServer which is Borland Enterprise Server Edition 5.2.1. Somehow EJB 2.0 doesn't want to work with it. Now I don't really want to know why is that because it was not the topic of the question. I have tested EJB 1.1 and it's working fine which is good enough for me. Initially i thought that something wrong with my code but after testing with EJB 1.1 i realized that there is nothing wrong with my code.

That's it.

0
 
aozarovCommented:
>> Any objections from you??
None from me :-)
Did you try "clManagerHome = (ClientManagerHome)ctx.lookup("ClientManager");" though? because it seems that  ClientManagerHome is not bound (jndi exception) but
"ClientManager" is bound  (as you get narrowed exception - after jndi).
0
 
worldsergaAuthor Commented:
Yes I did try clManagerHome = (ClientManagerHome)ctx.lookup("ClientManager"). It didn't help.

I think that my AppServer supports EJB2.0 but because of the configuration or whatever i have this kind of problems. It's ok, as i mentioned EJB1.1 is good enough for me.

Thanks to all of you.
0
 
suprapto45Commented:
Hi,

>> Any objections from you??
No...you solved it by yourself :).

Glad to know that you solve it.

Regards
Dave
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.