Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

EJBObject for new Entity Beans

 
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.
 
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
 
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.
 
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!
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic