Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • 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

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
10. @Resource SessionContext sessionCtx;
11. public Bar getBar()
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
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.
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!