Looking Under the Hood of a CMP Entity Bean

Figure 11.1 shows the interactions between the client, the EJB container, and the container-managed persistence bean.

Figure 11.1. Under the hood of a container-managed persistence bean.


The following steps describe the sequence of interactions in detail:

1.
At startup, the EJB container registers all deployed enterprise beans, including entity beans, with the JNDI service.

2.
The client looks up the home interface of the deployed enterprise bean via the Java Naming and Directory Interface (JNDI). In this example, the remote home interface for the Order bean can be located by using the following code segment:

Context initialContext = new InitialContext();
Object obj = initialContext.lookup("day11/Order");
OrderHome orderHome = (OrderHome)
 javax.rmi.PortableRemoteObject.narrow(obj, OrderHome.class);

3.
The client uses the remote home interface to create a remote Order object. In this example, the client creates a new order as follows:

Order order =  (Order)orderHome.create("1", "Submitted", 200.00);

When a client invokes a create<method> method on the home interface, the EJB container invokes the corresponding ejbCreate<method> method, followed by ejbPostCreate<method> method on the bean instance.

4.
The client calls a business method on the remote object. In this example, the client calls the getOrderId() method on the remote object as follows:

String orderId = order.getOrderId();

The container calls the appropriate method on the entity bean instance. For example, the EJB container calls getOrderId() method on the entity bean instance.

5.
The client calls the remove() method of the remote object. For example, the client removes the order object as follows:

order.remove();

The container calls the ejbRemove() method on the entity bean instance.

The EJB container synchronizes the state of the instance with the database by using the methods ejbLoad() and ejbStore(). For example, to passivate an entity bean instance, the container first calls ejbStore() to allow the instance to prepare itself for the synchronization of the database state with the instance's state, and then calls the ejbPassivate() method.

Unlike a bean-managed persistence entity bean, a container-managed persistence bean does not contain calls to access the database. The EJB container is responsible for persistence of a CMP entity bean. The container may use a persistence manager for persistence of entity beans. The persistence manager is responsible for performing the following tasks:

  • Creating an instance in a database

  • Loading the state of an instance in a database

  • Storing the state of an instance in a database

  • Activating the state of an instance

  • Passivating the state of an instance

  • Removing an instance from a database

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.144.108