Bean Managed Persistence   «Prev  Next»

Lesson 1

Bean-managed Persistent Entity Bean

How to create BMP

This modules covers writing the code for the entity bean, including the home interface, the remote interface, and the session bean class and the deployment descriptor.

Bean-managed persistence (BMP)

The data-access protocol for transferring the state of the entity between the entitybean instances and the underlying database is referred to as object persistence. In the last few sections we looked at the container-managed persistence model, wherein entity beans rely on the container to provide the persistence logic. The EJB specifications also support entity beans with bean-managed persistence (BMP) wherein the entity beans write explicit code to access the persistence store. For most users, accessing the persistence store involves writing JDBC code to access a relational database.
From a bean provider's perspective, this is more effort than the CMP model, because he or she must provide the logic to create, update, and remove the bean's state. However, bean-managed persistence is a viable choice in some circumstances. One benefit of BMP comes when mapping a bean's attributes to database fields proves to be difficult. This may occur if the bean state is defined by data in different databases. It can also occur if you are using a target data store that is a legacy system: You will probably need to access the store using a vendor-specific protocol rather than SQL commands, and the EJB container might not support the protocol. Bean-managed persistence is a good alternative to container-managed persistence when the container tools are inadequate for mapping the bean’s instance state to the underlying data source.
One major disadvantage of using a BMP (other than that it makes more work for the bean provider) is that it ties the bean to a specific database type and structure. Any change in the database schema will require a coding change in the bean class and it may not be a trivial change. With CMP, it is managed by the abstract persistence schema and thus is easier to accommodate.

Create and find methods

The first part of the module examines how to create an entity object and how to find it once created.

Remote interface and business methods

The next part covers the remote interface for the entity bean and the way that it invokes the business methods. You will find this is very similar to that of the session bean.

Container callbacks

The behavior of the container callbacks differs from that of session beans. You will be introduced to the differences in this module. Loading and storing the data from the persistent store is activated through the callbacks ejbLoad() and ejbStore().You will see how and when they are used. The course does not examine the JDBC code that is required to make the load and store function work with RDBMSs.
The JDBC [1](Java Database Connectivity package) methods are treated as black boxes.

The next lesson introduces the entity bean home interface and the create() methods.
[1]JDBC: Java database connectivity package that is used by Java programmers to access RDBMS.