Mapping enterprise bean JAR files (EJB modules) to relational database
(RDB) tables enables the EJB modules to access database resources.
About this task
You can map enterprise bean JAR files (EJB modules) to relational
database (RDB) tables using the EJB to RDB Mapping wizard of an assembly tool.
The wizard creates EJB to RDB mappings for the following situations:
- Existing enterprise bean but no database schema
- Top Down mapping generates a default database schema and a mapping
from one or more existing enterprise beans.
- Existing database schema but no enterprise bean
- Bottom Up mapping generates one or more enterprise beans and mappings
from an existing database schema.
- Existing enterprise bean and database schema
- Meet In the Middle mapping matches existing enterprise beans with
existing database tables. You can match by name, by name and type, or by neither.
Top-down and meet-in-the-middle mapping support multiple
backends, making multiple deployments inside a single EJB module configurable
at run time. Bottom-up mapping only supports a single backend. A backend can
represent different database vendors, or simply alternative mappings and table
qualifiers. If multiple backends exist, then current BackendID needs to be
set in the EJB deployment descriptor editor (when working with EJB 2.0 beans).
This mapping is used at run time when the JAR is installed on WebSphere Application
Server. When deploying EJB 1.1 beans inside an EJB 2.0 project, the EJB 1.1
beans are deployed only once, using the first declared database and type.
You specify a Backend ID in an EJB deployment descriptor editor under WebSphere
Bindings. The Backend ID determines the persister classes that
get loaded at deployment.
Procedure
- In the Project Explorer view, right-click the EJB module.
- Click EJB to RDB Mapping > Generate Map.
- After the wizard opens, press F1 and select a type of mapping.
The online help provides detailed information on generating a mapping.
- For EJB 2.0 projects, on the EJB to RGB Mapping page specify whether
you want to create a new backend (Top Down) or use an existing backend
(Bottom Up or Meet In the Middle) where the schema exists in
the backend but without a mapping file. If you previously generated a mapping,
you can create and map unmapped elements or open the mapping editor to manually
make changes. In EJB 2.0, your mapping and schema files make up
a backend for EJB 2.0 projects. You can have multiple backend folders
for each project; for example, one DB2 and one Oracle backend. The wizard
uses one database backend only as the default, but you can define as many
as you need.
- Follow the instructions in the wizard and in the online help.
- Click Finish to generate the mapping.
Results
Files for the updated module are shown in the Project Explorer view.
What to do next
After testing your module, you can
deploy your module to an application server.
For EJB
modules, you can generate EJB deployment code and deploy the module to a target server in one step. In the
Project Explorer view, right-click on the EJB project and click Deploy.