Generating a bottom-up mapping using an existing database
This task describes how to generate a bottom-up mapping when you want to create EJBs from tables in an existing database connection or database view.
Prerequisite tasks
- Enable the J2EE and Database Capabilities. You can complete this as follows:
- In the workbench preferences page (Window > Preferences) expand the folder Workbench , select Capabilites.
- Under the Capabilities list, select the Enterprise Java check box underAdvanced J2EE. Click OK.
- Create a JDBC connection.
Steps for this task
To generate enterprise beans and map based on a bottom-up mapping approach from a database connection or view:
- In the Database Explorer view of the Data perspective, expand the tree and select the database or database connection, and, optionally, specific database tables or views associated with the database or connection. You can select multiple database views and/or connections, as well as multiple tables and/or views.
- Right-click and select Create EJBs from Tables. This option will not be available if you have the mapping editor open.
- In the EJB project combination box, you can type a new project name or select an existing enterprise application project from the drop-down list. If you type a new project name a new EJB project will be created automatically for you when you click the Next button. Optionally, click the New button to launch the New EJB Project wizard if you wish to set additional options for the new project. See Creating an EJB project for detailed instructions on this page of the wizard.
- Select the tables from the database that you want to import into your project as EJBs, and click Next. If you selected only a database or database connection in the Database Explorer view, you will have to specify which tables will be used for the creation of EJBs. If you selected specific tables and/or views, then the check-boxes for those tables will already be marked.
- 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.
- 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.x 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.
- In the Package for generated EJB classes field, type the package name for the generated EJB classes.
- 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.
- 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.- Click Finish to generate the enterprise beans and the bottom-up mapping based on the database views that you selected in the wizard.
Parent topic
Generating a bottom-up mapping
Feedback