Oracle® Application Server TopLink Mapping Workbench User's Guide
10g Release 2 (10.1.2) Part No. B15900-01 |
|
Previous |
Next |
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.
Use this procedure to automatically generate SQL scripts to create the tables in a project.
To Generate SQL Scripts from Database Tables:
Select the database table(s) in the Navigator pane.
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.
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. |
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:
Select the database table(s) in the Navigator pane.
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.
Click Yes. The Generate Classes and Descriptors dialog box appears.
Use this table to enter data in each field:
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.
Description of the illustration 11mapbtn.gif
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.
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.
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:
Select the database table(s) in the Navigator pane.
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.
Click Yes to save your project before generating EJB entities. The Generate Enterprise Java Beans dialog box appears.
Enter a package name, select any persistence type options, and click on OK.
Description of the illustration 11mapbtn.gif
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.
Repeat step 5 for all appropriate sets of tables.
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.
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:
Select the database table(s) in the Navigator pane.
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.