Skip Headers

# Generating EJB Entity Beans and Descriptors From Database Tables

Previous

Next

Using TopLink Workbench, you can automatically generate EJB entity beans and descriptors for each database table, including the following:

- One EJB descriptor that implements the `<javax.ejb.EntityBean>` and entity bean classes

- Bean relation attributes (CMP or BMP)

- Java source for each class

- EJB-compliant method stubs

  Note: This option is available only for projects with container-managed or bean-managed persistence. See "Configuring Persistence Type" for more information.

To automatically generate EJB entity beans and descriptors for each database table, use this procedure:

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

2. Right-click the table(s) and choose Generate EJB Entities and Descriptors from > Selected Table or All Tables from the context menu. TopLink Workbench prompts you to save your project.

   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 EJB Entity Classes and Descriptors dialog box appears.

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

Field | Description
--- | ---
Package Name | Name of the package to contain the generated entity beans and descriptors.
Generate Local Interfaces Foot 1 | Specify if TopLink creates local interfaces for the EJB entity beans.
Generate Remote Interfaces Footref 1 | Specify if TopLink creates remote interfaces for the EJB entity beans.

Footnote 1 For CMP and BMP projects only. See "Configuring a Descriptor With EJB Information" for more information.

If the table contains foreign key fields that may represent relationship mappings, then the Choose Relationships to Generate dialog box appears. Select a potential relationship and click the 1:1 Mapping or 1:M Mapping button, located between the Potential Relationships and Selected Relationships windows.

You can also specify if the relationships are bidirectional (see "Configuring Bidirectional Relationship").

Repeat for all appropriate sets of tables.

Click OK to generate the relationship mappings.

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

See Also

Generating EJB Entity Beans and Descriptors From Database Tables