• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubtful question

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic