File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Will I have two shopping carts? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Will I have two shopping carts?" Watch "Will I have two shopping carts?" New topic
Author

Will I have two shopping carts?

Vishy Anand
Greenhorn

Joined: Mar 20, 2004
Posts: 5
I have recently started reading HFEJB and into the third chapter now. I have a question on isIdentical?

The book says, isIdentical(Object o) always returns false for stateful session beans. Say, we have a ShoppingCart Stateful Session Bean. I obtain its component interace (or a stub to EJBObject) from its home interface (or stub of EJBHome). I put some stuff into the cart and now say some how I lost the reference to the component interface. Now is there no way to get the reference to the same component interface? I am thinking that calling create on the stub to the home interface will create another Session Bean on the server for the statement given in the book to be true. So I end up with a new and empty shopping cart? Am I right, here?

I hope my question is clear
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

The book says, isIdentical(Object o) always returns false for stateful session beans.

YES. If the 2 beans are stateful bean, even the content is the same, isIdentical() returns false.

But if the 2 beans are stateless bean which come from the same home, isIdentical() returns true.


Say, we have a ShoppingCart Stateful Session Bean. I obtain its component interace (or a stub to EJBObject) from its home interface (or stub of EJBHome). I put some stuff into the cart and now say some how I lost the reference to the component interface. Now is there no way to get the reference to the same component interface?

YES, you will get a new EJBObject if you lose the old reference. Unless you save the EJBObject locally for future use, otherwise, if you lose it, you lose it forever.


I am thinking that calling create on the stub to the home interface will create another Session Bean on the server for the statement given in the book to be true. So I end up with a new and empty shopping cart? Am I right, here?

YES. For every create() call, you will create a NEW EJBObject, and thus, those old information are gone!

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Vishy Anand
Greenhorn

Joined: Mar 20, 2004
Posts: 5
Thanks Cheung. It looked kind of weird initially for me, but now makes sense to me. Thanks again, for the reply.
Vishy Anand
Greenhorn

Joined: Mar 20, 2004
Posts: 5
Now what if I pass the same stub to the component Interface of a StatefulBean? Will it still return false?

Example:

ShoppingCart sc = scHome.create();
What does sc.isIdentical(sc) return for stateful beans?
Vishy Anand
Greenhorn

Joined: Mar 20, 2004
Posts: 5
Waiting for the reply on the above question. Any EJB expert out there, reading this?
Vitaliy Geraymovych
Greenhorn

Joined: Jun 15, 2004
Posts: 24
Originally posted by Vishy Anand:
Waiting for the reply on the above question. Any EJB expert out there, reading this?


Not an expert

But result will be true. Spec. page 66.

V.


SCBCD 1.3<br />SCJP 1.2<br /> <br />"Every time I learn something new, it pushes some old stuff out of my brain" H.Simpson
Vishy Anand
Greenhorn

Joined: Mar 20, 2004
Posts: 5
Thanks Vitaliy. For pointing me toward the specs. I have gone through the Client's view of Sesson Bean chapter on the spec and it was easier to understanf than the HFEJB book. It may be only because I have already read it in HFEJB Book.

Anyway Thanks again and from now onwards I will also refer the spec.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Will I have two shopping carts?