Skip Headers

# Generating Classes and Descriptors From Database Tables

Previous

Next

TopLink 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, TopLink Workbench does the following:

- 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 (nonforeign 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 classes and descriptors from database tables, use the following procedure:

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

2. Right-click the table(s) and choose Generate Classes and Descriptors from > Selected Table or All Tables from the context menu.

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

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

   Complete each field on the Generate Classes and Descriptors dialog box and click OK.

   Use the following information to enter data in each field:

   Field | Description
   --- | ---
   Package Name | Specify the name of package to generate. The package name must comply with Java naming standards.
   Generate Accessing Methods | Specify if TopLink Workbench generates accessing methods for each class and descriptor.

If the table contains foreign key fields that may represent relationship mappings, then the Choose Relationships to Generate dialog box appears.

Select an entry from Potential Relationships and click the 1:1 Mapping or 1:M Mapping button, located between the Potential Relationships and Selected Relationships windows. See Understanding Relational Mappings for more information on mappings.

You can also specify whether the relationships are bidirectional. See "Configuring Bidirectional Relationship" for more information.

Click OK to automatically create the relationships.

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