Why to use Home interface to create instance of bean? Instead direct lookup? (ejb 2.1)

186 views Asked by At

i can't understend why in all guides write to use this:

SayHiRemote sayHiRemote = InitialContext
            .<SayHiHomeRemote> doLookup(SayHiHomeRemote.JNDI_GLOBAL_NAME)
            .create();
sayHiRemote.hi();

Instead of just :

SayHiRemote sayHiRemote = InitialContext
            .<SayHiRemote> doLookup(SayHiRemote.JNDI_GLOBAL_NAME);
sayHiRemote.hi();

What profit of "create()" method if no arguments (Stateless Session Bean) required?

1

There are 1 answers

0
Brett Kail On BEST ANSWER

Prior to EJB 3, it was not possible to directly look up a stateless session bean. There is no real benefit other than consistency with other bean types, which is why it was removed in EJB 3.

There remains a benefit for stateful session beans, because the create method is the factory method, so if you switch to EJB, you lose type-safety (cast vs create() return type) and depending on the relative speed of JNDI vs home.create(), you probably lose some performance.