Generating a bottom-up mapping using an existing EJB project

This task describes how to generate a bottom-up mapping when you want to use an EJB project that already exists on your workspace.

Prerequisite tasks

  1. Enable the J2EE and Database Capabilities. You can complete this as follows:

    1. In the workbench preferences page (Window > Preferences) expand the folder Workbench , select Capabilites.

    2. Under the Capabilities list, select the Enterprise Java check box underAdvanced J2EE. Click OK.

  2. Create an enterprise application project.

  3. Create an EJB project in the enterprise application project you just created.

Steps for this task

To generate enterprise beans and map based on a bottom-up mapping approach:

  1. In the J2EE perspective, right-click the EJB project for which you want to generate the bottom-up mapping and select Generate > EJB to RDB Mapping. 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 For bottom-up mapping only one backend is supported. 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 bottom-up mapping.

  4. Select Bottom-up and click Next.

  5. Complete the Database Connection page and click Next. See Creating JDBC connections for detailed instructions on this page of the wizard. If you have already completed this step once, you can select the Use existing connection check box and select an existing connection from the drop-down list.

  6. Select the tables and views from the database that you want to import, and click Next.

    • In order to avoid broken foreign keys, the wizard imports any required tables.

    • If you plan on using a bean to update a view, make sure that the view supports updates. The wizard does not check whether a view can be updated.

  7. If you are working with an EJB 1.x project, under the CMP Version drop-down list, the EJB specification level for generating the enterprise beans defaults to 1.x. If you are working with an EJB 2.x project, you have the option to select one of the following under the CMP Version drop-down list to specify the EJB specification level for the generated enterprise beans:

    • 1.x

    • 2.x

    Note: For EJB 2.0 enterprise beans, the bottom-up mapping only generates local interfaces because it is normally considered best practice for entity beans to only contain local interfaces.

  8. In the Package for generated EJB classes field, type the package name for the generated EJB classes.

  9. Optional: In the Prefix for generated EJB classes field, you can add a prefix name that gets added to the unique names generated by the mapping tool to avoid collision of new table mappings to existing CMP entity beans.

  10. If you selected to import and map a view, you can choose whether or not you want to create additional beans for the tables in the view. By default, the Do not generate beans for tables included in views check box is selected, and the wizard will not create these beans.
    Tip: When you do a bottom-up mapping, by default the wizard does not generate beans for underlying tables for views. However, because relationships need to be created for foreign keys, the wizard automatically creates a bean for any table that has any foreign keys or whose primary key is pointed to by any foreign keys from other tables. If you clear the Do not generate beans for tables included in views check box, the wizard generates beans for all tables and views in the database schemata.

  11. Click Finish to generate the enterprise beans and the bottom-up mapping based on the database tables and views that you selected in the wizard.

 

Parent topic

Generating a bottom-up mapping

Feedback