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 of entity beans: Bean-Managed Persistence(BMP) and Container-Managed Persistent(CMP). This article covers an example of a CMP, more specifically, a CMP application migration. 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:
- CMP implementation analysis
- Sample application
- The JBoss environment
- The Geronimo environment
- Step-by-step migration
- Summary
CMP implementation analysis
CMP implementation may vary from one vendor to another. The purpose of this section is to provide a CMP specific feature-to-feature comparison between JBoss v4 and Apache Geronimo M5 so you can clearly identify the differences and plan accordingly before migration.
Feature |
JBoss v4 |
Geronimo M5 |
---|---|---|
EJB Container |
JBoss AS 4.0 comes with its own EJB Container implementation. |
Geronimo uses OpenEJB as its EJB Container. |
Sample application
The Loan CMP 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 CMP application consists of the following packages:
- com.ibm.demo.entity.client
- CMPClient
***contains the main class that is called from the console.
- CMPClient
- 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
Tools used
The tools used for developing and building the Loan BMP sampple application are:
Eclipse
The Eclipse IDE was used for development of the sample application. This is a very powerful and popular open source development tool. Integration plug-ins are available for both JBoss and Geronimo. Eclipse can be downloaded from the following URL:
Apache Maven
Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM). Maven can manage a project's build, reporting and documentation from a central piece of information.
For this migration example Maven 1.0.2 was used. Maven can be downloaded from the followinf URL:
Sample database
The sample database for the Loan CMP application has only one table. This is an in-memory table. The MEMORY storage engine creates tables with contents that are stored in just in memory. These were formerly known as HEAP tables.
The following table describes the fields of the CUSTOMER table.
Field |
data type |
---|---|
id |
INTEGER |
name |
VARCHAR(45) |
birthdate |
DATE |
sss_no |
VARCHAR(25) |
address |
VARCHAR(60) |
annual_salary |
DOUBLE |
loan_amount |
DOUBLE |
The JBoss environment
This section shows you how and where the sample JBoss reference environment was installed so you can map this scenario to your own implementation. Note that for this migration example JBoss v4.0.2 was used.
Detailed instructions for installing, configuring, and managing JBoss are provided in the product documentation. Check the product Web site for the most updated documents.
The following list highlights the general tasks you will need to complete to install and configure the initial environment as the starting point for deploying the sample application.
- Download and install JBoss v4 as explained in the product documentation guides. From now on the installation directory will be referred as <jboss_home>
- Create a copy of the default JBoss v4 application server. Copy recursively <jboss_home>\server\default to <jboss_home>\server\<your_server_name>
- Start the new server by running the
run.sh -c <your_server_name>
command from the <jboss_home>\bin directory. - Once the server is started, you can verify that it is running by opening a Web browser and pointing it to this URL: http://localhost:8080. You should see the JBoss Welcome window and be able to access the JBoss console.
- Once the application server is up and running, the next step is to install and configure all the remaining prerequisite software required by the sample application. This step is described in the following section.
Install and configure prerequisite software
In order to build and run the Loan CMP application included in this article, you need to install and configure the build tool and the database that is used by the application.