File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Accesing 3.0 bean from 2.0 bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Accesing 3.0 bean from 2.0 bean" Watch "Accesing 3.0 bean from 2.0 bean" New topic
Author

Accesing 3.0 bean from 2.0 bean

Satya P
Greenhorn

Joined: Jul 01, 2008
Posts: 8
Hi,

In ENTHUWARE mock tests, explanation about a question is given as follows:

�A 2.0/2.1 bean can access a 3,0 bean as follows

Context initCtx = new InitialContext();
TaxHome taxHome = (TaxHome) PortableRemoteObject.narrow(initCtx.lookup("java:comp/env/ejb/tax"), TaxHome.class);
Tax tax = (Tax) taxHome.create();

Notice that the above client code uses the standard EJB 2.x client programming model. It does not need to know that the target bean is implemented with EJB 3.0.


Question:
---------

My understanding is that in a 3.0 EJB's business object is retreivd when we look up in JNDI.
initCtx.lookup("java:comp/env/ejb/tax").
How is the above code getting te HOME object?
3.0 EJB does not have a home, then how will the above code work?
sanjeev mehra
Ranch Hand

Joined: Feb 12, 2001
Posts: 93
How is the above code getting te HOME object?
3.0 EJB does not have a home, then how will the above code work?

I think, annotation tells container to create home/component interface.
Life cycle for SLSB/MDB is same for EJB2.x & EJB3; requirement to create bean is same; & programmers work is done by container.
Satya P
Greenhorn

Joined: Jul 01, 2008
Posts: 8
Hi Sanjeev,
Thanks for the reply.

As you said container might create the home object.

Now my question is what is stored in the JNDI under the name
"java:comp/env/ejb/tax".

When I perform a lookup from a 3.0 EJB to this EJB (which is also 3.0 EJB), I get the business object directly when I perform the lookup.

initCtx.lookup("java:comp/env/ejb/tax").


and when I perform the lookup from a 2.0 EJB this 3.0 EJB using the same string, I get a home object.

TaxHome taxHome = (TaxHome) PortableRemoteObject.narrow(initCtx.lookup("java:comp/env/ejb/tax"), TaxHome.class);

I am not able to understand how is this possible? Does the container take care internally all such issues? But how?
sanjeev mehra
Ranch Hand

Joined: Feb 12, 2001
Posts: 93
it may help;
I am not able to understand how is this possible? Does the container take care internally all such issues? But how?

In EJB 2; as you said, lookup+narrow+home then component;
EJB 3; container does all & client gets component;
HOW? then you would need to read specs for container.

EJB 3
If client is in EE environment & uses DI (dependency injection); client does not do lookup; container provides (injects) needed resource.
[ July 02, 2008: Message edited by: sanjeev mehra ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accesing 3.0 bean from 2.0 bean