What is the diff between the two code? Properties prop=new Properties(); Context cxt=null; prop.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); prop.put(Context.PROVIDER_URL,"t3://localhost:80"); cxt=new InitialContext(prop); EmployeeHome home = (EmployeeHome)cxt.lookup("emp"); Employee emp = home.create();
I am not a expert in EJB. but narrow approach is mostly used for RMI IIOP type of remote intanciation. As looks to be the case in the 2nd code. In the first case the JNDI might be getting the bean for local beans too. Steve
SCJP1.4,SCWCD, SCBCD, SCEA part 1<br />"Its feels good to know the stuff in detail."
The PortableRemoteObject.narrow tells you this is a Remote client view. So that's not a problem. If you do NOT see a narrow(), on the exam, you can say with absolute 100% certainty that you are seeing a LOCAL client view. Even though it is *possible* depending on your vendor, to NOT use a narrow() with a Remote view, that would not be according to the spec, and on the exam, you are to answer ONLY according to the spec. But that's not the part that bothers me. What bothers me is that this code is this: Sequence sRemote = (Sequence) sHome.create() ; There should NEVER need to be a cast of the return from create(). Remember, create() is declared with the correct return type -- the type of the component interface -- so there should NEVER be a cast. Doesn't mean it will hurt you, but it should not be there, and is never needed. The ONLY things that need to be cast are things that are not returned with the correct declared return type. That means JNDI context lookup() and also getEJBObject() or getEJBHome() on the handle objects. In addition, you need a narrow as well as a cast if those things-declared-without-the-specific-return-type are Remote stubs. So, things which must be cast: * result of JNDI lookup * result of a call to a handle method Things which must be narrowed: * result of JNDI lookup if the client view is Remote (which means the thing coming back is a stub) * ALL calls to a handle (because handles are ONLY for Remote client views) * Any thing else that might return a stub, unless the method's return type is the Remote interface type. ======================== cheers, Kathy