• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

SCBCD: Entity Beans and SetEntityContext

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic