• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question about STFB Local business interface

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic