Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

no Local EJB in thread ?  RSS feed

 
al Dupin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody !

I use timer.schedule() to launch small batches.
My problem is that I don't have access anymore to local EJB in those batch.
(With websphere 5.1)

In my web project, i can load local EJB without problem using initialContext.lookup("java:comp/env/ejb/myLocalEJB")
but in my batch, nope, error :
javax.naming.NameNotFoundException: Name "comp/env/ejb" not found in context "java:".

With initialContext.getNameInNamespace(), i found the same context "localhost/nodes/localhost/servers/server1" in a web servlet and in the batch. So I don't understand why cannot access this local EJB.

My understanding is that EJB are on the same serveur instance, so can be accessible in local , no ?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This really belongs in the EJB forum, so I'll move it there...

Where is this "batch" that you're referring to running?

In the application server?

In the same web application as the servlet you mentioned?

The reason that "java:comp/env/ejb/myLocalEJB" works in the servlet is because an <ejb-ref> has been defined in the web.xml of the web application that points to the real JNDI of the EJB. "java:comp/env" is a special JNDI subcontext defined for each web application or EJB deployment, and all the things inside of it are defined in the web app's or EJB's deployment descriptor.

If this "batch" that you refer to is in a different web application, you'll need to copy the <ejb-ref> from the original one to be able to access the EJB in this way. If the "batch" is not running in the application server, then you won't be able to access the EJB, since you said it's defined as local.
 
al Dupin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for choosing wrong forum.

the batch process is launch in the same web application.

I don't understand how the jndi context work, because the ejb-local-ref definition in the web.xml are ok, and thats's work good in the servlet.

I have put exactly the same code to retreive the local EJB in the servlet and batch.

maybe the use of timer.schedule is not a good way to launch a batch.
but in jdk 1.3, i don't now how to otherwise.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!