Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Session Beans method to be called from session bean  RSS feed

 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As we all know that for calling a method of a different bean
from one bean we have to first get the ejbobject and then call the method
for calling a entity bean from session bean
we first of all create primary key object using primarky key class and then use findByprimaryKey to get the ejb object
and subsequently call the method of entity bean
can anyone tell me how to do the same procedure if we have to call session bean's method from our current session bean?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get a reference to the session beans home object and then run the create method.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gaurav,

I agree with Thomas. The only way I know of to invoke a method on
a bean (any type, from anywhere) is to first get a reference to
the bean's remote interface, and the only way to do that for a
session bean (that I know of), is to lookup the bean's home
interface and then invoke the "create" method. For an entity bean
-- as you say -- you can use "findByPrimaryKey".


Of-course, that's why (IMO) the EJB 2 spec introduces the local
home interface and local remote interface -- so that a session
bean can more easily and more quickly get a reference to another
bean's remote interface.


Good Luck,

Avi.

------------------
 
hanumanth reddy
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Obtain the Initail context and then look up for the Home nad one you obtained the home object then call its create method to ogtain the remote object
try the following code and make it suit to your case

private static EJBRemote getRemote() throws RemoteException
{
try {
javax.naming.Context context getInitialContext();
EJBHome home = (EJBHome)context.lookup("lookupname");
return home.create();
} catch (Exception e) {
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!