It's not a secret anymore!*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Doubtful question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Doubtful question" Watch "Doubtful question" New topic
Author

Doubtful question

Muthaiah Ramanathan
Ranch Hand

Joined: May 16, 2005
Posts: 102
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!
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

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.
Muthaiah Ramanathan
Ranch Hand

Joined: May 16, 2005
Posts: 102
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.!!!

Can anyone explain?
[ March 07, 2006: Message edited by: Muthaiah Ram ]
p anish
Ranch Hand

Joined: Feb 26, 2005
Posts: 32
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.
Balaji Anand
Ranch Hand

Joined: Nov 03, 2004
Posts: 146
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
 
GeeCON Prague 2014
 
subject: Doubtful question