Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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

HF Concept in Head First

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I got some confusion while reading HF. Following are the points i am seeking some clarification:
1) In HFE i found that for every bean instance created by the container, there is a new context object created. is it right? That means bean context object is conceptually different from servlet context object()?
2) In HFE i found that when client calls a create method on entity bean. A new instance of the bean as well as context is created and these two objects are linked together. Next the context object as well as the EJBObject is associated with that particular primary key.
if this is the case, than what is the use of having a bean pool because bean is associated with one context object and this context object has one primary key. In this case bean is always associated with one entity in the database thus it can never serve a different client whose EJBObject has a different PK than this beans context.
3) Is there any way we can update the mass data like mass select i.e. Home Business method. I mean something like updateAll()? or we need to take individual ejbObject and update the relevant data?
Thanks in advance.
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajeev,
1) Right.
2) Wrong . When a client calls create() on the home interface of an entity bean, a new bean instance is *not* created (or not necessarily). In fact entity bean creation and entity bean instantiation are totally unrelated. You're right by saying that the context object is associated with the bean instance for its whole life. *BUT*, the context object is mutable, meaning that its state may change over the time, including the primary key.
3) With BMP beans, you'll do whatever you want by using JDBC. With CMP beans (but as I lack of EJB *real experience*, please correct if I am wrong), you'll have to loop through the collection of component interfaces returned by your ejbSelect*() method, and call setters on them.
Regards,
Phil.
[ January 05, 2004: Message edited by: Philippe Maquet ]
 
Rajeev Gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your prompt reply
*BUT*, the context object is mutable, meaning that its state may change over the time, including the primary key.
Could you give me some resource from where i can verify this information?
Thanks
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The EJB specs.
No kidding now, the javax.ejb.EntityContext API doc does confirm that (I put the boldface myself) :

The EntityContext interface provides an instance with access to the container-provided runtime context of an entity enterprise Bean instance. The container passes the EntityContext interface to an entity enterprise Bean instance after the instance has been created.
The EntityContext interface remains associated with the instance for the lifetime of the instance. Note that the information that the instance obtains using the EntityContext interface (such as the result of the getPrimaryKey() method) may change, as the container assigns the instance to different EJB objects during the instance's life cycle.


Regards,
Phil.
 
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic