0

Given only the fully qualified class name/interface name of the Session Bean, is it possible to instantiate call a method on it from a POJO?

If yes, how?

Thanks, TheLameProgrammer

TheLameProgrammer
  • 4,037
  • 5
  • 19
  • 16
  • Session Beans are usually created by your application server when there is a new client (session). Are you trying to write your own application server? – Peter Lawrey Sep 07 '11 at 11:22
  • @Peter, I got your point. I need to call a method on an EJB that is managed by the Application Server. I have updated my question. Sorry for the misunderstanding. – TheLameProgrammer Sep 07 '11 at 12:29

2 Answers2

0

see Accessing Enterprise Beans

Accessing Local Enterprise Beans Using the No-Interface View Client access to an enterprise bean that exposes a local, no-interface view is accomplished through either dependency injection or JNDI lookup.

To obtain a reference to the no-interface view of an enterprise bean through dependency injection, use the javax.ejb.EJB annotation and specify the enterprise bean’s implementation class:

@EJB
ExampleBean exampleBean;

To obtain a reference to the no-interface view of an enterprise bean through JNDI lookup, use the javax.naming.InitialContext interface’s lookup method:

ExampleBean exampleBean = (ExampleBean)
InitialContext.lookup("java:module/ExampleBean");
exampleBean.yourMethod();
mambolis
  • 173
  • 3
  • 6
0

Since EJB3.0 a session bean is a POJO as well, so you could instatiate it as any other class by

MyEJB ejb = new MyEJB();

But as Peter Lawrey pointed out correctly, this should be done by an application server.

In order to answer your question, you should provide more details, what you plan to do and what you have come up with so far.

PS: And allthough you name yourself lame, you should work on your accept rate...

Alexander Rühl
  • 6,769
  • 9
  • 53
  • 96