Exercise 1.4: Mapping entity beans to relational databases

Before you begin, you must complete Exercise 1.3: Adding entity beans to class diagrams.

Exercise 1.4 teaches you how to create the database mapping files for CloudscapeTM. It explains the files created and their use. In this module, you will do these tasks:

Overview

Next, you will map the entity beans to a relational database. Mapping involves creating database definition files for the tables that will be used to store the entity bean's fields. Generally, each bean uses a different table. Fields in the bean represent columns in the table. Key fields in the bean correspond to primary keys in the database table.

Database mapping results in a set of files that are discussed later. These files are packaged with the EJB. They are also used by an administrator to create the database tables when putting the EJB application into production. The database mapping files are dependent on the database type.

You can create a set of database mapping files for one or several database types, which are listed below.

This approach, creating database definitions from existing entity beans, is called top-down mapping. The reverse process, bottom-up mapping, is also provided, where you create entity beans from existing database tables. Meet-in-the-middle mapping is also available, for use when you have existing enterprise beans and existing database tables. See Mapping enterprise beans to database tables for more information.

Mapping relational databases from entity beans

To create mapping files for Cloudscape, follow these steps:

  1. On the class diagram, highlight the Author bean.
  2. Right-click and select EJB to RDB Mapping > Generate Map. The EJB to RDB Mapping wizard opens.
  3. On the first page, select Create a new backend folder.
  4. Click Next.
  5. Select Top-Down as the type of mapping.
  6. Click Next.
  7. On the Top-Down Mapping Options page,
    1. Select Cloudscape V5.1 as the Target Database.
    2. Use UMLEJB as the Database name.
    3. Leave NULLID as the Schema name.
    4. Leave the other options as they are.
  8. Click Finish. The mapping files are created and the Author table is visualized on the class diagram.
  9. Select Ctrl + S to save the class diagram.

Author Table on class diagram

In the Project Explorer view, under EJB Projects > UML EJB tutorial > ejbModule > META-INF > backends, you will see the folder CLOUDSCAPE_V51_1 which contains the mapping files listed below. Another view of the mapping relationships can be found in EJB Projects > UML EJB tutorial > Deployment Descriptor > Maps directory. You can locate the newly mapped table in the Project Explorer view by selecting the table on the class diagram, right-clicking and selecting Navigate > Show in > Data Definition View.

Now you are ready to begin Exercise 1.5: Finishing the EJB creation process.

Terms of use | Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.