• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about STFB Local business interface

 
vitesse wei
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
question:

A developer writes a stateful session bean FooBarBean with two local business interfaces Foo
and Bar. The developer wants to write a business method called getBar for interface Foo that
returns a Bar reference to the same session bean identity on which the client invokes getBar.
Which code, when inserted on Line 12 below, implements the getBar method with the wanted
behavior?
10. @Resource SessionContext sessionCtx;
11. public Bar getBar()
12.
13. }
A. return (Bar) this;
B. return (Bar) new FooBarBean();
C. return (Bar) sessionCtx.lookup("FooBarBean")
D. return (Bar) sessionCtx.getBusinessObject(Bar.class);
E. lnitialContext ic = new lnitialContext();
return (Bar) ic.lookup("java:comp/env/ejb/FooBarBean");

given answer is D,I want know why A,C,E are wrong?
 
Adam Tkaczyk
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JEE servers use Proxy mechanisms to obtain references on EJB objects through business interface. With proxy, container can react on some properties thirled to business methods like @TransactionAttribute or @RolesAllowed.

Even if you return reference on Bar interface it will not be business interface connected to EJB object, so probably you get an exception when you invoke some method from it. That is why answer A) is wrong. Try java.lang.reflect.Proxy for more details. It is great fun.

C) and E) are wrong because lookup method will return reference to the new EJB object, not the same used for method invocation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic