Overview
An entity bean is defined as a representation of persistent data that has the ability to read from database and populate its fields with data. It can be updated and stored back to the database. There are two types: Bean-Managed Persistence(BMP) and Container-Managed Persistent(CMP). This article covers the migration of a BMP sample application. For this type of entity bean, actual code must be written to handle persistent operations such as loading, saving and finding data. The developer must use persistence API such as JDBC to select, insert, update, delete from a database.
This article is organized in the following sections:
- BMP implementation analysis
- Sample application
- The JBoss environment
- The Geronimo environment
- Step-by-step migration
- Summary
BMP implementation analysis
BMP implementation may vary from one vendor to another. The purpose of this section is to provide a BMP specific feature-to-feature comparison between JBoss v4 and Apache Geronimo so you can clearly identify the differences and plan accordingly before migration.
Features |
JBoss v4 |
Geronimo |
---|---|---|
EJB Container |
JBoss comes with its own EJB Container implementation. |
Geronimo uses OpenEJB as its EJB Container. |
JMS implementation |
JBoss is packaged with JBoss MQ. |
Geronimo uses ActiveMQ as its JMS implementation. |
Sample application
The Loan BMP application is very simple. When the command line client is run, an entry is made into the database. The findByPrimaryKey() method of the CustomerHomeRemote interface is called and the field values of the returned CustomerRemote object are printed to the console. This is followed by a call to the findBySssNo() method after which the field values of the returned CustomerRemote object are printed to the console.
The following figure illustrates the application flow:
The user runs the command line client which then either creates an entity bean (which then adds itself to the datasource) or asks for one, by primary key, which is created from information that is stored in the database.
Application Beans
The Loan BMP application consists of the following packages:
- com.ibm.demo.entity.client
- BMPClient
- contains the main class that is called from the console.
- BMPClient
- com.ibm.demo.entity.bmp
- CustomerBean
- Implements javax.ejb.EntityBean fields of the bean are defined here.
- Contains business methods corresponding to the methods exposed by the CustomerRemote interface.
- Conatins callback methods that are called by the container to manage the bean. These methods include the create and find methods which use jdbc to make entries to the database and to search the database.
- Has a helper method that looks up the datasource through jndi.
- CustomerRemote
- Interface that extends javax.ejb.EJBObject.
- Exposes the setter and getter methods of the EJB.
- CustomerHomeRemote
- Interface that extends javax.ejb.EJBHome.
- Exposes the create and find methods of the EJB.
- CustomerBean