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?
[ 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!
That's a good question, and worth a trial. The point I'm particularly interested in is that the code looks up the bean using its special JNDI context. In theory, both manager1 and manager2 could be used to retrieve the same home interface. In that case, I'm pretty sure the isIdentical() would return true.
Oops. It does return false. But why? In HFEJB, it is given that for two stateless session bean objects, isIdentical() would always return true, even if it comes from two different beans.!!! --- isIdentical() will return true if the two beans comes from same home.
refer to page 141 of HF. for a stateless bean... isIdentical will return true for any two beans from the same home. Since this bean is deployed twice they are considered different...
6.9.2 of the Spec ============== All session objects of the same stateless session bean within the same home have the same object identity, which is assigned by the container. If a stateless session bean is deployed multiple times (each deployment results in the creation of a distinct home), session objects from different homes will have a different identity. The isIdentical(EJBObject otherEJBObject) and isIdentical(EJBLocalObject otherEJBLocalObject) methods always returns true when used to compare object references of two session objects of the same stateless session bean. ============== I think "same stateless session bean" means session beans from the same home
Hope this helps
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop