Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Will I have two shopping carts?

 
Vishy Anand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Vishy Anand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cheung. It looked kind of weird initially for me, but now makes sense to me. Thanks again, for the reply.
 
Vishy Anand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Waiting for the reply on the above question. Any EJB expert out there, reading this?
 
Vitaliy Geraymovych
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vishy Anand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic