Guys,
I am very doubtful about the below question, that I came across in
www.ejbCertificate.com. Pls help me, if it is the other way.
Question:Consider the following fragment of client code involving stateless session beans. Which of the following statements regarding this code is true? Assume that all reference variables have been declared
properly and the code has been compiled successfully.
4. Context initialContext = new InitialContext();
5. AccountMgrHome accountMgrHome1 = (AccountMgrHome)
6. initialContext.lookup("java:comp/env/ejb/accountmgr1");
7. AccountMgrHome accountMgrHome2 = (AccountMgrHome)
8. initialContext.lookup("java:comp/env/ejb/accountmgr2");
9. AccountMgr accountmgr1 = accountMgrHome1.create();
10. AccountMgr accountmgr2 = accountMgrHome2.create();
Choices:
1. A stateless session bean cannot be deployed multiple times in the same container.
2. A remote home interface is located through a JNDI lookup.
3. The home interface provides a method to get the EJBMetaData interface for the session bean.
4. The home interface provides a method to get a handle that can be serialized and written to stable storage for the session object.
5. Calling accountmgr1.isIdentical(accountmgr2) returns false.
Answer:
Answer 5 is correct. In the code, a stateless session bean is deployed multiple times where each deployment results in the creation of a distinct home. Session objects with different homes will have different identities, therefore calling accountmgr1.isIdentical(accountmgr2) will return false.
Answer 1 is incorrect. Multiple instances of a specific stateless session bean can be deployed in a container where each stateless session bean instance is unique. Answer 2 is incorrect. After performing a JNDI lookup to locate the home interface, the client code between lines 5 and 8 do not perform a PortableRemoteObject.narrow() on the home object. Therefore, the home interface can be considered as a local home interface.
Since the home interface is local, its corresponding component interface is also local. A handle for a session object and the EJBMetaData interface cannot be obtained from a local component interface, making answers 3 and 4 incorrect.
In the code, a stateless session bean is deployed multiple times where each deployment results in the creation of a distinct home. Session objects with different homes will have different identities, therefore calling accountmgr1.isIdentical(accountmgr2) will return false. Is this right?
Regards,
Muthaiah.
[ March 07, 2006: Message edited by: Muthaiah Ram ]
[ March 07, 2006: Message edited by: Muthaiah Ram ]
SCJP 1.6, SCJD, SCWCD, SCBCD.
Be nice to people on the way up cos, you'll need 'em on your way down - From somewhere I can't remember!