Generating a top-down mapping

In the top-down mapping approach, you generate a default database schema and mapping based on one or more existing enterprise beans.

In EJB 2.x, your mapping and schema files make up a backend for EJB 2.x projects. You can have multiple backend folders for each project (for example, one DB2 and one Oracle backend). Only one database backend is used as the default, but you can define as many as you need. So, the first page in the EJB 2.x mapping wizard asks you to specify whether you want to create a new backend, in which case you then proceed as outlined here, or you can use an existing backend, like for meet-in-the-middle or bottom-up1 where only the schema exists in the backend (no map file). If you have previously generated a mapping, you can choose to create and map unmapped elements or open the mapping editor to manually make changes.

To generate a schema and map from existing enterprise beans using the top-down mapping approach:

  1. In the J2EE perspective, right-click the EJB project and select EJB to RDB Mapping > Generate Map. This option will not be available if you have the mapping editor open.

  2. For EJB 2.x projects, select whether to Create a new backend folder or to Use an existing backend folder. If you choose to use an existing backend, and if you have previously generated a mapping, choose one of the following options at this point:

    • Create and map unmapped elements: use this option if you have made changes to the backend or to the enterprise beans and want to create the new elements and update the map accordingly.

    • Open mapping editor on selected backend map: use this option to open the mapping editor, where you can make manual updates to the mapping.

    Click Finish to perform the action and exit the wizard.

  3. If you choose to create a new backend folder, click Next to continue creating your initial top-down mapping.

  4. Select Top Down, and click Next.

  5. Select a Target Database.

  6. Type the Database name and Schema name.

  7. Optional: You can select one or both of the following check boxes:

    • Generate DDL

    • Add a column for collision detection: use this option for EJB 2.x CMP beans to add a column to your relational table. This column is reserved to determine if a record has been updated. For more information about this collision detection column, refer to the related topic about adding a column for collision detection.

    • WebSphere 3.x Compatible - only select this option if you are migrating from WebSphere Application Server 3.x deployments.

  8. Click Finish to create the top-down mapping, or click Next to further define inheritance.

  9. If inheritance exists, select additional enterprise beans from the list to add a leaf table for each checked bean that joins with the parent table, then click Finish.

The EJB mapping tools create tables, columns, and constraints relating to a CMP bean and its fields, as well as a map of each CMP field to a column. You can then make any required changes to these maps using the Mapping editor. Use the relational database tools to modify the tables and columns.

 

Related tasks

Adding a column for collision detection when generating a top-down mapping

1 Bottom-up mapping is not available