Generating a meet-in-the-middle mapping

You can use the meet-in-the-middle approach of mapping enterprise beans to database tables if you have existing enterprise beans and an existing database schema. The Mapping wizard generates a map.mapxmi file based on matches that it finds between the enterprise beans and the database tables. In most cases, you will still need to open the map.mapxmi file in the Mapping editor to completely configure the mapping.

To generate a meet-in-the-middle mapping:

  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 meet-in-the-middle mapping.

  4. Select Meet in the Middle, and click Next.

  5. Specify one of the following types of matching that you want to use for the meet-in-the-middle mapping:

    • None: the wizard maps the EJB JAR to the database, but does not map database elements to enterprise bean elements.

    • Match by Name: the wizard maps based on exact matches of bean names and table names. It also maps exact matches of attribute and column names.

    • Match by Name and Type: the wizard maps based on matching names, then also maps based on matching types.

  6. If you have not already imported the database tables into the EJB project, the wizard opens the Database Connection page. See Creating JDBC connections for detailed instructions on this page of the wizard. If you have already completed this step once, you can also select the existing connection from the drop-down list.

  7. Click Finish. The wizard generates a mapping file based on the meet-in-the-middle options that you specified.

You can now open the map.mapxmi file in the Mapping editor and further configure the mapping. The wizard will not always match every bean or attribute, so you need to make sure that each field of an enterprise bean is mapped to the corresponding column of a table within the selected schema. You also need to map each association role to a foreign-key relationship. Configure your mapping until all persistent features of the enterprise beans are mapped to a component within the schema.

Restriction:

  • Matching by name will only handle exact matches. If you generated your schema using the WebSphere Application Server Version 3.5 compatible switch or imported a WebSphere Application Server Version 3.5 JAR, your table names are appended with 'tbl' and will not be recognized.

  • In inheritance mapping, the children beans will not be mapped if they do not have fields of their own. You need to map these to the parent table by hand.