Skip Headers

Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Understanding the EJB Entity Beans With BMP Architecture

BMP is the part of the J2EE component model that lets you, the bean provider, implement the entity bean's persistence directly in the entity bean class or in one or more helper classes that you provide.

This architecture is an extension of the three-tier architecture, in which the persistent data is bean managed within an entity bean using code that you implement. The client code accesses the data through the entity bean interface.

TopLink BMP is an extension of the TopLink persistence framework that provides base class `BMPEntityBase` as a starting point for your BMP development. This class provides an implementation for all methods required by the EJB specification (except `ejbPassivate`). Subclass `BMPEntityBase` to create a TopLink-enabled BMP entity bean.To use the `BMPEntityBase` class, perform the following:

1. Create a TopLink session (see "Understanding TopLink Sessions") for your application.

2. Add a `BMPWrapperPolicy` to each descriptor that represents a BMP entity bean.

   The `BMPWrapperPolicy` provides TopLink with the information to create remote objects for entity beans and to extract the data out of a remote object.

3. Create the home and remote interfaces.

4. Create deployment descriptors (see "Integrating TopLink With an Application Server ``" and "Creating TopLink Files for Deployment").

5. Package your application (see "Packaging a TopLink Application").

6. Deploy the beans (see "Deploying a TopLink Application").

To make full use of TopLink session and unit of work features, TopLink provides a hook into its functionality through the `BMPDataStore` class. Use this class to translate EJB-required functionality into simple calls.

The `BMPDataStore` class provides implementations of `LOAD` and `STORE`, multiple finders, and `REMOVE` functionality. The `BMPDataStore` class requires a TopLink session. A single instance of `BMPDataStore` must exist for each bean type deployed within a session. When creating a `BMPDataStore`, pass in the session name of the session that the `BMPDataStore` must use to persist the beans and the class of the bean type being persisted. Store the `BMPDataStore` in a global location so that each instance of a bean type uses the correct `store` method.

TopLink BMP support (see Figure 2-7) lets you combine the standard interfaces of BMP entity beans with TopLink flexibility, performance, and productivity.

Figure 2-7 Three-Tier BMP Architecture

Description of "Figure 2-7 Three-Tier BMP Architecture"

TopLink supports BMP with EJB 1.1 and EJB 2.0. To use BMP support with EJB 2.0, the home interface must inherit from the `oracle.toplink.ejb.EJB20Home`. To make calls to the `BMPEntityBase`, the `findAll` method must call the EJB 2.0 version of the methods. These methods are prefixed with `ejb20`. For example, in the EJB 2.0 version, the `findAll` method appears as `ejb20FindAll`.

To use local beans, use the `oracle.toplink.ejb.EJB20LocalHome` setting instead of the default `oracle.toplink.ejb.EJB20Home`. Instead of the `oracle.toplink.ejb.BMPWrapperPolicy` setting, use the `oracle.toplink.ejb.bmp.BMPLocalWrapperPolicy` setting.

To accommodate both local and remote configurations, ensure the following:

- For a bean that has a single interface, use the corresponding wrapper policy (local or remote) for the descriptor.

- Beans can only participate in relationships as either local or remote interfaces, not both.

For more information, see the following:

- "Integrating TopLink With an Application Server ``"

- "Creating TopLink Files for Deployment"

- "Packaging a TopLink Application"

- "Deploying a TopLink Application"

- "Configuring Persistence Type"

- "Configuring the Server Platform"

## Example Implementations

An example of the EJB entity beans with BMP implementation is a Model-View-Controller Model 2 architectural design pattern that runs in a J2EE container, with servlets and JSP that access session beans and EJB 2.0-compliant BMP entity beans enhanced by TopLink.

## Advantages and Disadvantages

Using BMP with a TopLink three-tier architecture offers the following advantages:

- It simplifies the BMP method calls. These can be inherited from an abstract bean class, rather than being generated.

- TopLink makes BMP easier to implement.

- It enables developers to implement database-independent code in the bean methods.

- The architecture supports features such as complex relationships, caching, object-level and dynamic queries, and the unit of work.

The main disadvantages of BMP include the following:

- You must create the persistence mechanisms in the bean code.

- It is not as transparent or efficient as CMP.

- TopLink-only Java object applications offer the same degree of independence from the application server.

## Technical Challenges

The key technical challenge in this architecture lies in integrating components into a cohesive system. For example, this architecture requires a specific TopLink integration with the application server or J2EE container.

Other issues include the following:

- External JDBC Pools

- JTA/JTS Integration

- Cache Coordination

### External JDBC Pools

By default, TopLink manages its own connection pools. You can also configure TopLink to use connection pooling offered by the host application server. This feature is useful for shared connection pools and is required for JTA/JTS integration (see "Configuring External Connection Pooling").

### JTA/JTS Integration

JTA and JTS are standard Java components that enable sessions to participate in distributed transactions. You must configure TopLink to use JTA/JTS to use session beans in the architecture (see "Integrating the Unit of Work With an External Transaction Service").

### Cache Coordination

If you choose to use multiple servers to scale your application, you may require TopLink cache coordination (see "Understanding Cache Coordination").