Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Anchor
top
top

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.

...

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

Apache Geronimo M5

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
Anchor
sampleApp
sampleApp

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:

Image RemovedImage Added

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.

...

  • com.ibm.demo.entity.client
    • BMPClient
      • contains the main class that is called from the console.
  • 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.

In addition to these classes, the Loan BMP sample application provides a Web Application client with two JSPs (create.jsp and list.jsp).

Back to Top

Tools used

The tools used for developing and building the Loan BMP sampple application are:

...

This application is using the HSQL database that comes as part of the JBoss bundle. Open the hsqldb-ds.xml You need to modify the script for creating the database. Edit the localDB.script file located in the following directory:

<jboss_home>/\server/\<your_server_name>/deploy directory and which sets up the default datasource. Near the \data\hypersonic

Add at the top of the localDB.script file , look for the <connection-url> element. Uncomment this element and make sure the value is set to jdbc:hsqldb:hsql://localhost:1701 and that any other connection-url elements are commented out.

Now you need to modify the script for creating the database. Edit the localDB.script file located in the following directory:

<jboss_home>\server\<your_server_name>\data\hypersonic

Add at the top of the localDB.script file the content of the following example in order to create the sample HSQL database.

the content of the following example in order to create the sample HSQL database.

Note

Make sure JBoss is not running at the time of modifying this file.

CREATE MEMORY TABLE CUSTOMER(ID INTEGER NOT NULL PRIMARY KEY,NAME VARCHAR(45),BIRTHDATE DATE,SSS_NO VARCHAR(25),ADDRESS VARCHAR(60),ANNUAL_SALARY DOUBLE,LOAN_AMOUNT DOUBLE)

...

In order to build the loan application a Maven script has been provided. Download the Loan application from the following URL:link:

Loan BMP Samplehttp://opensource2.atlassian.com/confluence/oss/download/attachments/1148/loan-bmp.zip

After extracting the zip file, a loan-bmp directory will be created. From now on, this directory will be referred as <bmp_home>. In that directory open the project.properties file. Edit the maven.jboss.home property to match your environment. It is important that you use "//" on the windows platform as is done below.

maven.jboss.home=Z://JBoss-4.0.2<jboss_home>

From a command prompt or shell go to the <bmp_home> directory and run the following command:

maven ejb:ejb

This will build the jar file and war files and put it them in the <bmp_home>/apps/target foldertarget directory. The jar created by the Maven build contains a JBoss specific deployment descriptor, the jboss.xml file in located the META-INF directory of the JAR is shown in the following example:

...

To deploy the Loan BMP application in JBoss, copy the entity-ejb-SNAPSHOT.jar file and entity-ejb.war files you just built with Maven to the following directory:

...

To test the sample client application type the following command from the <bmp_home> directory:

maven run:client

The result of this command is a list of loans that were retrieved from the database similar to the list shown following in the follow:

When you run this command, you will receive a list of all the loans that were retireved from the database, you should see a screen similar to the one shown in the following example:

No Format
bgColor#000000
borderStylesolid
E:\loan-bmp>maven run:client
 __  __
|  \/  |__ _Apache__ ___
| |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
|_|  |_\__,_|\_/\___|_||_|  v. 1.0.2

build:start:

run:client:
    [java] creating customer...
    [java] done.findByPrimaryKeyTest... 1
    [java] customer name: Customer 1
    [java] customer sss no: 2323232
    [java] customer loan amount: 0.0
    [java] customer annual salary: 0.0
    [java] customer birthdate: Fri Oct 21 15:40:39 EDT 2005
    [java] updating ejb...
    [java] done.findBySssNoTest... 2323232
    [java] customer name: Customer 2
    [java] customer sss no: 2323232
    [java] customer loan amount: 0.0
    [java] customer annual salary: 0.0
    [java] customer birthdate: Fri Oct 21 15:40:39 EDT 2005
BUILD SUCCESSFUL
Total time: 3 seconds
Finished at: Fri Oct 21 15:40:39 EDT 2005

E:\loan-bmp>

Back to Top

To test the sample Web application point your browser to:

http://localhost:8080/entity-ejb

You should see the following screen:

Image Added

Click on Add Customer. Enter the new customer information then click Create, this will take you to the first page showing the updated list of customers.

Back to Top

The Geronimo environment
Anchor
Geronimo
The Geronimo environment
Anchor
GeronimoGeronimo

Download and install Geronimo from the following URL:

...

CREATE TABLE CUSTOMER(ID INTEGER NOT NULL PRIMARY KEY,NAME VARCHAR(45),BIRTHDATE DATE,SSS_NO VARCHAR(25),ADDRESS VARCHAR(60),ANNUAL_SALARY DOUBLE,LOAN_AMOUNT DOUBLE)

Image RemovedImage Added

Back to Top

...

Configure Maven

You should set the maven.geronimo.home property in project.properties to point to your <geronimo_home> directory.

Back to Top

Step-by-step migration
Anchor
migration
migration

...

The same EJB jar file that was created and deployed in jboss may be deployed in Geronimo with no changes to its contents but you still need to edit the jndi properties of sample client application. Edit the jndi.properties file located in in the <bmp_home>/jndi directory as shown in the following example:

...

Code Block
xml
xml
borderStylesolid
titlecustomer-ejb.xml
<?xml version="1.0" encoding="UTF-8"?>

<openejb-jar
    xmlns="http://www.openejb.org/xml/ns/openejb-jar"
    xmlns:naming="http://geronimo.apache.org/xml/ns/naming"
    xmlns:security="http://geronimo.apache.org/xml/ns/security"
    xmlns:sys="http://geronimo.apache.org/xml/ns/deployment"
    configId="geronimo/CustomerEJB/1.0/car"
    parentId="orggeronimo/apache/geronimo/SystemDatabasesystem-database/1.0/car">
 <enterprise-beans>
    <entity>
        <ejb-name>CustomerEJB</ejb-name>
        <jndi-name>CustomerHomeRemote</jndi-name>
        <local-jndi-name>CustomerRemote</local-jndi-name>
        <resource-ref>
            <ref-name>jdbc/ibm-demo</ref-name>
            <resource-link>SystemDatasource</resource-link>
        </resource-ref>
    </entity>
 </enterprise-beans>
</openejb-jar>

This plan sets orggeronimo/apache/geronimo/SystemDatabasesystem-database/1.0/car as the parent. What follows is the definition of the entity bean. The jndi-name element indicates the jndi name of the entity bean's home interface CustomerHomeRemote. This is the name that the Loan BMP sample applicationwill application will lookup in the jndi context. The element local-jndi-name indicates the jndi name of the local interface, which in this case happens to be a remote interface, CustomerRemote. Next, a reference to the SystemDatasource is defined giving the application access to the database.

Build the Loan BMP application by typing maven ejb from the <bmp_home> directory. This will create the entity-ejb-SNAPSHOT.jar The Web Application client can be directly deployed in Geronimo. This is because the build step packages both the JBoss jboss-web.xml and Geronimo geronimo-web.xml specific deployment plans in the war file. You can see both of these files in the <bmp_home>/target directory.

Back to Top

Deploy the migrated application

To deploy the migrated Loan BMP application, make sure the Geronimo server is up and running.

From a command line, change directory to <geronimo_home> and type the following command:

java -jar bin/deployer.jar --user system --password manager deploy <bmp_home>/target/entity-ejb-SNAPSHOT.jar <bmp_home>/dd/customer-ejb.xml

With this command you first tell the deployer tool where is the module to deploy, then you tell the deployer tool how to deploy the application by specifying the deployment plan.

From the command line change the the <bmp_home> directory and type the following command:

<bmp_home>/maven run:client

Current error

No Format
bgColor#000000
borderStylesolid

E:\loan-bmp>maven run:client
 __  __
|  \/  |__ _Apache__ ___
| |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
|_|  |_\__,_|\_/\___|_||_|  v. 1.0.2

build:start:

run:client:
    [java] javax.naming.AuthenticationException: Cannot deternmine server protocol version: Received null/0.0; nested exception is:
    [java]      java.io.IOException: Unable to read protocol version.  Reached the end of the stream.
    [java]      at org.openejb.client.JNDIContext.authenticate(JNDIContext.java:196)
    [java]      at org.openejb.client.JNDIContext.getInitialContext(JNDIContext.java:181)
    [java]      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
    [java]      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
    [java]      at javax.naming.InitialContext.init(InitialContext.java:219)
    [java]      at javax.naming.InitialContext.<init>(InitialContext.java:175)
    [java]      at com.ibm.demo.entity.client.EntityBeanClient.getInitialContext(EntityBeanClient.java:74)
    [java]      at com.ibm.demo.entity.client.EntityBeanClient.main(EntityBeanClient.java:28)
BUILD SUCCESSFUL
Total time: 8 seconds
Finished at: Mon Oct 24 10:22:40 EDT 2005

E:\loan-bmp>

Back to Top

...

\src\webapp\WEB-INF directory.

The geronimo-web.xml deployment plan should look like the following example.

Code Block
xml
xml
borderStylesolid
titleGeronimo deployment plan geronimo-web.xml

<web-app xmlns="http://geronimo.apache.org/xml/ns/web"
         xmlns:naming="http://geronimo.apache.org/xml/ns/naming"
         configId="geronimo/EntityDemoWebApp/1.0/car"
         parentId="geronimo/CustomerEJB/1.0/car">
         
    <context-root>entity-ejb</context-root>    
     
    <ejb-ref>
        <ref-name>ejb/CustomerHome</ref-name>
        <target-name>
             geronimo.server:EJBModule=geronimo/CustomerEJB/1.0/car,
                 J2EEApplication=null,J2EEServer=geronimo,
                     j2eeType=EntityBean,name=CustomerEJB
        </target-name>
    </ejb-ref>
</web-app>

Build the Loan BMP application by typing maven from the <bmp_home> directory. This will create the entity-ejb-SNAPSHOT.jar and entity-ejb.war in the <bmp_home>/target directory.

Back to Top

Deploy the migrated application

To deploy the migrated Loan BMP application, make sure the Geronimo server is up and running.

From a command line, change directory to <geronimo_home> and type the following command:

java -jar bin/deployer.jar --user system --password manager deploy <bmp_home>/target/entity-ejb-SNAPSHOT.jar <bmp_home>/dd/customer-ejb.xml

With this command you first tell the deployer tool where is the module to deploy, then you tell the deployer tool how to deploy the application by specifying the deployment plan.

Deploy the Web Application by typing the following command:

java -jar bin/deployer.jar --user system --password manager deploy <bmp_home>/target/entity-ejb.war

From the command line change the the <bmp_home> directory and type the following command:

maven run:client

You should see something similar to the following example:

No Format
bgColor#000000
borderStylesolid

E:\loan-bmp>maven run:client
 __  __
|  \/  |__ _Apache__ ___
| |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
|_|  |_\__,_|\_/\___|_||_|  v. 1.0.2

build:start:

run:client:
    [java] creating customer...
    [java] done.findByPrimaryKeyTest... 1
    [java] customer name: Customer 1
    [java] customer sss no: 2323232
    [java] customer loan amount: 0.0
    [java] customer annual salary: 0.0
    [java] customer birthdate: Thu Oct 27 00:00:00 EDT 2005
    [java] updating ejb...
    [java] done.findBySssNoTest... 2323232
    [java] customer name: Customer 2
    [java] customer sss no: 2323232
    [java] customer loan amount: 0.0
    [java] customer annual salary: 0.0
    [java] customer birthdate: Thu Oct 27 00:00:00 EDT 2005
BUILD SUCCESSFUL
Total time: 4 seconds
Finished at: Thu Oct 27 18:59:44 EDT 2005

E:\loan-bmp>

Test the applications the same way you tested on JBoss.

Back to Top

Summary
Anchor
summary
summary

This article covered how to migrate a sample application, from JBoss to the Apache Geronimo application server. You followed step-by-step instructions to build the application, deploy and run it, and then migrate it to the Geronimo environment.

The following list summarizes the major differences found during this sample application migration.

  • In the Geronimo specific deployment plan, the ejbreference name is mapped to the gbean name of the ejb unlike in the JBoss specific deployment descriptor where the resource name is mapped to the JNDI name of the ejb.
  • In order to deploy a datasource in JBoss you need to just copy the configuration file to the deploy directory but in Geronimo you need to use the deployer tool or the Web console.

...

Back to Top