The bean Home

Every Session and Entity bean has a Home.

Message-driven beans don’t have homes because message-driven beans don’t have a client view (in other words, client’s can’t get a reference to a Message-driven bean).

The Home has one main job: to hand out references to a bean’s Component interface. For a Session bean, that’s just about all you’ll do with the bean’s Home. For Entity beans, though, the Home plays a much bigger role.

Each deployed bean has its own Home, and that Home is responsible for all bean instances of that type. For example, if you deploy a ShoppingCart Session bean, the container will create one ShoppingCart bean Home. That ShoppingCart Home takes care of all the instances of ShoppingCart beans. In other words, if 2,000 clients each want their own ShoppingCart bean reference (which, remember, means a reference to the ShoppingCart bean’s Component interface), the one and only ShoppingCart Home will hand out all 2,000 references.

If you deploy three beans as part of an application, say, a ShoppingCart, Customer, and Product, there will be three Homes in the server representing each of those deployed beans. It makes no difference how many EJBObjects and stubs the Home objects hand out, there will still be only three Homes.

So does that mean that for each Home there is only a single instance of the class that implements the Home interface for that bean type? Not necessarily, but that’s exactly how we’re supposed to think about it. We’ll actually refer to the Home ...

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.