Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accesing 3.0 bean from 2.0 bean

 
Satya P
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic