Readme for the AutoWorld
example
This example illustrates CMP entity beans
built using root/leaf inheritance. Vehicle is the root enterprise
bean from which all of the leaf enterprise beans are derived. The
leaves include RaceCar, Bus and SUV. In addition, the AutoWorld example
includes one-to-many relationships for Garage and MotorVehiclePart, and
a custom composer for VapUSPhoneNumber (an entity field of Vehicle).
Finally, finders are employed on all enterprise beans to find all instances
of the persistent objects.
Contents
This example includes eight enterprise
beans which demonstrate the following relevance:
-
Vehicle - the root enterprise bean whose
CMP fields include: id, dateAcquired, and cellphone
-
Automobile - inherits from Vehicle and
adds CMP field: numberOfAirBags
-
RaceCar - inherits from Automobile and
adds CMP field: topSpeed
-
Bus - inherits from Vehicle and adds CMP
field: maximumPassengers
-
Truck - inherits from Vehicle and adds
CMP fields: maximumLoad, numberOfWheels
-
SUV - inherits from Truck but adds no
additional CMP fields
-
Garage - has a one-to-many association
with Vehicle and contains CMP fields: id, capacity
-
MotorVehiclePart - has a many-to-one association
with Vehicle and contains CMP fields: partId, description
After creating the example project for
the AutoWorld example, double-click the AutoWorldEJB module within the
EJB Modules of the J2EE Hierarchy view to open it in the EJB Editor. This is the
editor where the beans were created and can be edited. In preparation
for running the example, export the database tables for AutoWorldEJB , and generate
deploy and RMIC code.
Finally, create a WebSphere Test Environment Server where the AutoWorld
enterprise beans can be tested using the IBM EJB Test Client.
Restriction: Currently, any
EJB mapping that contains more than one table must remove any constraints
related to these tables in the database. Without the database constraints
turned off, RI ordering problems arise producing RemoteExceptions. Further
details about this restriction can be found in the EJB Tooling README under
"Ordering problems producing RemoteExceptions".
Running AutoWorld
After creating the AutoWorldExample, follow
these steps:
Setting up the database:
If you do not already have the AutoWorld
tables in your SAMPLE DB2 database in DB2, then you will need to run the
schema Table.ddl file to create the tables:
- Open the Data perspective by choosing Window > Open Perspective > Other... Data.
-
In the Data Definition view, expand the AutoWorldExample project to ejbModule/META-INF/Table.ddl.
-
Open the context menu on the Table.ddl file and select Run on server....
- Enter the necessary connection information for your database and click on the Finish button.
Enabling JDBC 2.0 on DB2:
If you have not already enabled JDBC 2.0
on DB2 then you will need to run the usejdbc2.bat file.
-
Stop all DB2 processes.
-
From a command prompt run the usejdbc2
batch file in <DB2_INSTALL_PATH>\SQLLIB\java12,. where <DB2_INSTALL_PATH>is the path where you installed DB2.
-
Reboot your system and restart DB2.
Important: If you are denied access
when running the usejdbc2.bat file, you have not stopped all of the DB2
processes.
Setting up a server and server configuration:
- Open the Server perspective by clicking Window > Open Perspective > Other... Server
- Click File > New > Server and Server Configuration.
- Type or select the following values:
- Server name: Server for AutoWorld.
- Folder: AutoWorldSRV.
- Server type: WebSphere v4.0 Servers/Test Environment.
- Template: None.
- Click Finish.
Modifying the server configuration and adding a data source:
-
From the Server Configuration view, select
Server Configurations/Server for AutoWorld > Add > DefaultEAR
from the pop-up menu
-
From the Server Configuration view, select
Server Configurations/Server for AutoWorld > Open from the pop-up
menu
-
Click on the Data source tab
-
In the listbox JDBC driver list: , select Db2JdbcDriver
(COM.ibm.db2.jdbc. DBCConnectionPoolDataSource):
-
For the listbox Data source defined for the JDBC driver selected above, click Add, then enter the following values:
- Name: Sample Database
- JNDI name: Sample
- Database name: SAMPLE
- Default user ID: (your DB2 user ID)
- Default user password: (your DB2 user password)
-
Click OK
-
From the File menu, select Close and save the server for AutoWorld.
Running on the IBM EJB Test Client:
-
From the Navigator view, select AutoWorldExample
> Run on Server from the pop-up menu.
-
Click on the JNDI Explorer and expand
the autoworld.ejbgroup to find all of the AutoWorld beans.
-
Click on the beans to see their Home interfaces
and then start creating and manipulating the AutoWorld example enterprise
beans. You can use tools shipped with your database to verify the persistence
of your newly created beans by inspecting the contents of the database
tables. For a detailed description of how to use the IBM EJB Test Client,
refer to the Server Tools documentation in WebSphere Studio.
Running this example using a DB2 Universal Database for iSeries database:
You can optionally set up the Auto World example to access a database that
is running on iSeries.
See Database access using the iSeries for detailed instructions about creating the server configuration, creating
the database on the iSeries, creating the new data source for the database,
and configuring the data source on the iSeries.
Documentation
For detailed information on the topics
illustrated by the AutoWorld example, please refer to documentation provided
in the following online help topics:
-
Developing enterprise beans - overview
-
Implementing custom finder helpers for
CMP entity beans
-
Adding methods to the home and remote
interfaces
-
Adding and Editing CMP fields
-
Generating a top-down mapping
-
Creating and editing relationships (associations)
-
Setting EJB deployment descriptor properties
-
Generating EJB deployment code from the
workbench
-
Creating or editing EJB access beans
-
Testing EJB projects - overview
-
Creating a server instance and configuration
(together)
-
Setting a server instance to use a server
configuration
-
Adding a project to a server configuration
-
Starting server instance
-
Using the EJB test client
Limitations
This document assumes that you have DB2
installed and a working SAMPLE database.
Disclaimer:
The following [enclosed] code is sample
code created by IBM
Corporation. This sample code
is not part of any standard IBM product
and is provided to you solely for
the purpose of assisting you in the
development of your applications.
The code is provided 'AS IS',
without warranty or condition of any
kind. IBM shall not be liable for any damages
arising out of your use of the sample
code, even if IBM has been
advised of the possibility of such damages.