Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJBObject for new Entity Beans

 
David McJames
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
On page 338 of HF EJB, it states that by the time you are in the ejbPostCreate method - an EJBObject for the new entity has eiter been created or found. Should this not only be created? How can an EJBObject be found?
The EJBObject has a primary key, right? And the entity also has the same primary key, right? So if we create a new entity, either this entity does not exist (and therefore no EJBObject exists) or an Exception is thrown, becuase the entity already exists.
Or am I wrong?
Cheers in advance.
 
Girija Siva
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David
If two clients are trying to access the same entity then both clients have reference to same EJBObject. That is why an EJBObject for the new entity has eiter been created or found.
See page 99 of HFEJB for the architectural overview
 
Weerawit Maneepongsawat
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David McJames:

On page 338 of HF EJB, it states that by the time you are in the ejbPostCreate method - an EJBObject for the new entity has eiter been created or found. Should this not only be created? How can an EJBObject be found?

It's may be come from the pool, after ejbCreateXXX() the container may create new EJBObject for get it from pool.
The EJBObject has a primary key, right? And the entity also has the same primary key, right? So if we create a new entity, either this entity does not exist (and therefore no EJBObject exists) or an Exception is thrown, becuase the entity already exists.

The EJBObject will have primary key after container move EJBObject from pool state to ready state, that mean you can get ref to EJBObject and Entity that exist.
Fix me..
 
David McJames
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
Thanks for your replies, but this is still unclear for me.
If two clients try to access the same entity, then they share the same EJBObject. Thats fine. But if two clients try to CREATE the same entity, then one of them should get a CreateException (or DuplicateKeyException). My point is that when you CREATE a new entity, a new EJBObject must also be craeted. This is because no EJBObject can already exist with this primary key. Otherwise a DuplicateKeyException would be thrown. Or is the primary key of an existing EJBObject changed?
Thanks again.
 
Weerawit Maneepongsawat
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David McJames:
Hi guys,
Thanks for your replies, but this is still unclear for me.
If two clients try to access the same entity, then they share the same EJBObject. Thats fine. But if two clients try to CREATE the same entity, then one of them should get a CreateException (or DuplicateKeyException). My point is that when you CREATE a new entity, a new EJBObject must also be craeted. This is because no EJBObject can already exist with this primary key. Otherwise a DuplicateKeyException would be thrown. Or is the primary key of an existing EJBObject changed?
Thanks again.


Please take a look at
10.5.1 Instance life cycle

Ready state. An instance in the ready state is assigned an entity object identity.

The container will give primary key for ejbobject when it come back to ready state.
EJBObject can share for any entiry that have same home.
 
cyril vidal
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

On page 338 of HF EJB, it states that by the time you are in the ejbPostCreate method - an EJBObject for the new entity has eiter been created or found. Should this not only be created? How can an EJBObject be found?

To my sense, you are completely right, and HFE is in error while saying that you may find the EJBObject by the time you're in ejbpostCreate method .
If you're in this method, the EJBObject object is supposed to be created and is not supposed to be found --> so, as you say, you will get a DUplicateKeyException.
Some replies to your thread tell you may found an existing EJBObject during ejbActivate method applied to a bean that has been passivated. But the authors of these threads forgot one thing you are not allowed to call both ejbActivate and ejbCreate (and so ejbPostCreate. So, what happens to a passivated bean has nothing to do with ejbPostCreate method.
Well done David,
Regards,
Cyril.
 
David McJames
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the confirmation Cyril. I was begining to think I was wrong!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic