This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes SCBCD: Entity Beans and SetEntityContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "SCBCD: Entity Beans and SetEntityContext" Watch "SCBCD: Entity Beans and SetEntityContext" New topic
Author

SCBCD: Entity Beans and SetEntityContext

Jason Mowat
Ranch Hand

Joined: Aug 17, 2003
Posts: 79
Greetings,

In HFEJB, p. 327, it states that you can use your entity context to get a reference to your home. Does this imply that a home object will exist for entity beans in general, or that a home object will be created for each different type of entity bean before they are actually instantiated?

For example, I have 2 entity beans: CustomerBean and ProductBean. My container decides to create a few bean instances in the pool to serve as "actors" for these 2 entity beans. So, the constructor is called and the entity context is set. In the entity context, will I be able to get the home for entity beans in general, or is it more specific; does it create a home object for CustomerBean and a home object for ProductBean? If that's the case, are the beans in the pool "type-casted", meaning that will a bean instance in the pool only be capable of playing CustomerBean roles because it's entity context has it slaved to a customer home?

Thanks,
Jason
Sun Raj
Greenhorn

Joined: Mar 09, 2005
Posts: 11
The relation to a bean to its respective home object is many to one (typically, but some situations may warrent to have multiple home object each handling some set of beans).
Therefore for your CustomerBean object there should be a home (say CustomerHome) object. Otherwise, how will CustomerBean get instantiated? The create signatures of you CustomerBean is known only to the home (CustomerHome).
Therefore, every bean has a corresponding home object. The reference to the home object in the bean context refers to that bean's home object.

SN
Keerthi P
Ranch Hand

Joined: Aug 19, 2003
Posts: 203
In the entity context, will I be able to get the home for entity beans in general, or is it more specific; does it create a home object for CustomerBean and a home object for ProductBean?


Yes. But not within the no-arg constructor - It is accessible thru ejbContext in setEntityContext() and other methods.

According to the spec, the bean instance should assume that a home object is available in the setEntityContext() and other methods (except constructor). It is upto to the container implementation to have:
1. One EJBHome object for each instance of a bean from the same home.
2. One EJBHome object for all the instance of a bean from the same home.

But, there cannot be one global home object for all the beans in an enterprise application. Will it make sense? No. Because a home is a group of bean instances that belong to a particular family, which means that a home object will find or create a bean of a particular type only.


Cheers.<br />Keerthi<br />(SCJP, SCWCD, SCBCD)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SCBCD: Entity Beans and SetEntityContext
 
Similar Threads
HF Concept in Head First
Error while validate Descriptors
Bean in Entity bean pool lost identity?
ejbCreate in session bean
My SCEA Part 1Study Notes