Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

An EJB should behave as local and remote as well

 
padma warlu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want my EJB to behave as remote and local as well. If my EJB is being called from client ( say servlet ) then there sbould be a remote call. If my EJB is being called from any other EJB then it should be a local call.

Using local interfaces we can do. But my EJB should be remote and local as well.

for this i have an aproach. I dont know how far it is correct and reliable.

the aproach is as follows :

I will declare my EJB in the ejb-jar.xml for remote block and also for local block. but with different ejb names. I use remote ejb name to lookup from the servlet. and i use local ejb name to lookup from another EJB.
Will this be a good approach. Or there are any other alternatives to acheive this type of issue.

Thanks with Regards
Venkat
 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
What you are saying is correct, Your EJB will have 4 interfaces 2 Component interfaces & 2 local interfaces. As well as you have to write entries in ejb-jar.xml


Regards
Shrinivas
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I will declare my EJB in the ejb-jar.xml for remote block and also for local block. but with different ejb names. I use remote ejb name to lookup from the servlet. and i use local ejb name to lookup from another EJB.
Will this be a good approach. Or there are any other alternatives to acheive this type of issue.

If you have defined local interfaces for an EJB and is called from another EJB in the same container then you will always get the local instance. You don't need to name local and remote differently.
 
padma warlu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what if the same EJB is being called from the client ie servlet or jsp which is in the different container ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic