So how DID the client get a reference to the EJB object for #28?

When a client wants to call a business method on a specific entity (in other words, an entity with a unique primary key, like Lee Loo #28), the client first needs a reference to that entity’s EJB object.

For an entity bean, remember, there are three ways that can happen:

  1. Client calls a finder on the home

    customerHome.findByPrimaryKey("28");
  2. Client calls create on the home (to insert #28 for the first time)

    customerHome.create("Loo", "Lee","28", "54 Bar Circle");
  3. Client calls a home business method that returns a reference to the bean’s component interface

    customerHome.getCustomerByStreet("Bar Circle");

We’ll talk about each stage of the bean’s lifecycle for finders, creates, and home business methods. But first—each of these assumes that the bean instance already exists in the pool. But how does the bean get there in the first place?

image with no caption

Note

Before the client can use a bean for ANYTHING -- creation, finders, business methods, etc., the Container has to make a new bean instance for the pool. Bean CONSTRUCTION isn’t tied to entity bean CREATION.

Construction means a new bean instance. But creation, for an entity bean, means a new entity is inserted into the database.

CMP Entity bean construction

Scenario: Container wants to make a new bean instance for the pool

  1. Container makes a new EntityContext

  2. Container makes a new instance of the bean ...

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.