Skip Headers
Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2)
Part No. B15900-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Generating Data from Database Tables

The OracleAS TopLink Mapping Workbench can automatically generate the following information from the database tables.

You can also generate database tables from descriptors in your project.

Generating SQL Creation Scripts

Use this procedure to automatically generate SQL scripts to create the tables in a project.

To Generate SQL Scripts from Database Tables:

  1. Select the database table(s) in the Navigator pane.

  2. Right-click the table(s) and choose Generate Creation Script for > Selected Table or All Tables from the pop-up menu. The SQL Creation Script dialog box appears.

    You can also choose Selected > Generate Creation Script for > Selected Table or All Tables from the menu.

    Figure 3-6 SQL Creation Script

    Description of sqlscrip.gif follows
    Description of the illustration sqlscrip.gif

  3. Copy the script and paste it into a file. You may need to edit the file to include additional SQL information that the OracleAS TopLink Mapping Workbench could not generate.


    Note:

    If OracleAS TopLink cannot determine how a particular table feature should be implemented in SQL, it generates a descriptive message in the script.

Generating Descriptors and Classes from Database Tables

The OracleAS TopLink Mapping Workbench can automatically generate Java class definitions, descriptor definitions, and associated mappings from the information in database tables. You can later edit the generated information if necessary.

For each table, the OracleAS TopLink Mapping Workbench:

  • Creates a class definition and a descriptor definition.

  • Adds attributes to the class for each column in the table.

  • Automatically generates access methods, if specified.

  • Creates direct-to-field mappings for all direct (non-foreign key) fields in the table.

  • Creates relationship mappings (one-to-one and one-to-many) if there is sufficient foreign key information. You may be required to determine the exact mapping type.


    Note:

    Class and attribute names are generated based on the table and column names. You can edit the class properties to change their names.

To Generate Descriptors and Classes from Database Tables:

  1. Select the database table(s) in the Navigator pane.

  2. Right-click the table(s) and choose Generate Descriptors and Classes from > Selected Table or All Tables from the pop-up menu. The Save Project dialog box appears.

    You can also choose Selected > Generate Descriptors and Classes from > Selected Table or All Tables from the menu.

  3. Click Yes. The Generate Classes and Descriptors dialog box appears.

    Figure 3-7 Generate Classes and Descriptors

    Description of genclass.gif follows
    Description of the illustration genclass.gif

  4. Use this table to enter data in each field:

    Field Description
    Package Name Name of package to generate
    Generate Accessing Methods Specify if the OracleAS TopLink Mapping Workbench generates accessing methods for each class and descriptor

  5. Enter the information and click OK. If the table contains foreign key fields that may represent relationship mappings, then the Choose Relationships to Generate dialog box appears.

    Figure 3-8 Choose Relationships to Generate

    Description of choose.gif follows
    Description of the illustration choose.gif

  6. 1:1 Mapping button.
    Description of the illustration 11mapbtn.gif

    1:M Mapping button.
    Description of the illustration 1mmapbtn.gif

    Select a Potential Relationship and click the 1:1 Mapping or 1:M Mapping button. See Chapter 6, "Understanding Relationship Mappings" for more information on mappings.

    You can also specify whether the relationships are bidirectional.

  7. Click Create to automatically create the relationships (or click Skip to generate the descriptors without creating these relationships.).

The newly created descriptors appear in the Navigator pane of the OracleAS TopLink Mapping Workbench.

Generating EJB Entities from Database Tables

Use this procedure to automatically generate EJB classes and descriptors for each database table. Generating EJB entities allows you to create:

  • One EJB descriptor that implements the <javax.ejb.EntityBean> interface and four EJB 1.1 classes for each table

  • Bean relation attributes (CMP or BMP)

  • Java source fore each class

  • EJB-compliant method stubs


    Note:

    This option is available only for projects with CMP or BMP persistence.

To Generate EJB Entities:

  1. Select the database table(s) in the Navigator pane.

  2. Right-click the table(s) and choose Generate EJB Entities and Descriptors from > Selected Table or All Tables from the pop-up menu. The Save Project dialog box appears.

    You can also choose Selected > Generate EJB Entities and Descriptors from > Selected Table or All Tables from the menu.

  3. Click Yes to save your project before generating EJB entities. The Generate Enterprise Java Beans dialog box appears.

    Figure 3-9 Generate EJB Entity Classes and Descriptors

    Description of genejb.gif follows
    Description of the illustration genejb.gif

  4. Enter a package name, select any persistence type options, and click on OK.

  5. 1:1 Mapping button.
    Description of the illustration 11mapbtn.gif

    1:M Mapping button.
    Description of the illustration 1mmapbtn.gif

    If the table contains foreign key fields that may represent relationship mappings, then the Choose Relationships To Generate dialog box appears (see Figure 3–8). Select a potential relationship and click the 1:1 Mapping or 1:M Mapping button.

    You can also specify whether the relationships are bidirectional.

  6. Repeat step 5 for all appropriate sets of tables.

  7. Click Create to generate the relationship mappings (or click Skip to generate the EJB descriptors without creating these relationships.).

The system creates the remote primary key, home, and bean classes for each bean and adds this information to the project.

Generating Tables on the Database

Use this procedure to create a table in the database, based on the information in the OracleAS TopLink Mapping Workbench.

To Create a Table on the Database:

  1. Select the database table(s) in the Navigator pane.

  2. Right-click the table(s) and choose Create on Database > Selected Table or All Tables from the pop-up menu. The Save Project dialog box appears.

    You can also create tables by selecting Selected > Create on Database > Selected Table or All Tables from the menu.


    Note:

    You must log into the database before creating tables. See "Logging into the Database" for more information.

The OracleAS TopLink Mapping Workbench creates the tables on the database.

The newly created descriptor(s) appear in the Navigator pane of the OracleAS TopLink Mapping Workbench. Use the EJB Info tab (see Figure 4–16) to modify the EJB information.