EJB Entity Bean Modeler

Use the EJB Entity Bean Modeler wizard to begin the creation of entity beans based on existing tables in any database accessible through JDBC. You can use the wizard to create several entity beans at once, and you can specify any relationships between those beans.

Once you've used the Entity Modeler to generate the code that make up the beans, their primary keys, their home and remote interfaces, and the appropriate entries in the deployment descriptor, you can then modify the results using other JBuilder tools, such as the Bean designer, the Deployment Descriptor editor, and the JBuilder code editor.

To display the EJB Entity Bean Modeler wizard, choose File|New to display the object gallery, click the Enterprise tab, then double-click the EJB Entity Bean Modeler icon.

Step 1

Available EJB Groups

Displays a list of EJB groups that are defined in your current project. Select the EJB group you want this new enterprise bean to belong to. If no EJB groups are listed or you want to create a new EJB group for the enterprise bean, click the New button to start the Empty EJB Group wizard; once the Empty EJB Group wizard finishes, the Enterprise JavaBean wizard resumes.

Step 2

The second step establishes a connection to a JDBC data source.

Choose Existing Connection

Clicking the Choose Existing Connection button displays a Select Database dialog that displays existing database connections you might have already defined. If you select one of these existing connections and click OK, the remainder of the fields on the page are automatically filled in (except the Password field) with information about this existing connection.

Driver

Select the database driver you need to connect to your data source from the list of drivers. The list displays the drivers installed on your machine in black, while all other drivers are displayed in red.

URL

Specify the URL to your data source. The pattern the URL must assume depends on the selected driver. The ... button next to the URL field is enabled in some cases to help you define the URL. What happens when you click the ... button depends on the driver you have chosen.

Username

Specify a user name to access the data source.

Password

Specify a valid password to access the data source.

Extended Properties

Use the extended properties field to define additional connection properties your driver might be able to use. Clicking the ... button displays the Extended Properties dialog box to help you define extended properties.

JNDI Name

Specify the name the JNDI should use to locate the desired data source.

Step 3

Use this page to select the tables you want to map to entity beans.

Available

Lists all the available tables in your specified data source. Move the tables you want to create entity beans for to the Selected box. To move all the tables to the Selected box, click the >> button. To move a single table at a time, click the table name in the Available box and click the > button.

Selected

Lists all the tables you've selected to create entity beans for. This box is empty until you make your selections.

Step 4

Use this page to select the columns from each table to map to entity bean fields. You can also specify links between tables if you have more than one table.

Tables And Links

Each table you selected on the previous page appears here. If you want to specify a relationship between tables, you can do so with the Link Tables dialog box. Display the Link Tables dialog box either by dragging your between the two tables, or by choosing the Add Link button.

Add Link

Displays the Link Tables dialog box.

Edit Link

Displays the Link Tables dialog box to edit an existing relationship. Select one of the tables in the link in the Tables and Links box, then choose the Edit Link button.

Remove Link

Removes an existing link. Select one of the tables in the link in the Tables and Links box, then choose the Remove Link button.

Selected Table's Columns

Use these two boxes to determine which columns in the selected table are mapped to fields in the entity bean. To select a table, click one of the tables in the Tables and Links group. By default, all columns in the selected table are selected.

Available

The Available box lists all the columns in the selected table that have not been selected to map to fields in the entity bean.

Selected

The Selected box lists all the columns in the selected table that have been selected to map to fields in the entity bean. By default, all columns are selected.

Step 5

Use this page to map the columns of the table(s) to the fields in the entity bean(s).

Table

Displays a drop-down list of all the selected tables. Select the table you want to work with from this list. You must map the columns for all the tables before you go on the the next step.

Column-Field Mappings

Displays all the selected columns in the table you selected in the Table field. First, specify which field or fields make up the primary key. You must specify a primary key for each table.

The wizard suggests a default Field Type and Field Name for each column. You can accept these types and names, or you can change these to meet your needs. You won't be able to change the Column Name or Column Type fields, as these are the fields as they exist in the data source.

Finish mapping the columns for all the tables before you click Next.

Step 6

Use this page to specify the names of the package and the classes of the entity bean. You must complete this information for each table. JBuilder suggests values for these fields. You can accept them or change them as you wish.

Table

Use this drop-down list to select a table.

Bean Name

The name of the entity bean.

JNDI Bean Name

The name JNDI uses to locate the bean.

Home Interface

The name of the entity bean's home interface.

Remote Interface

The name of the entity bean's remote interface.

Bean Class

The name of the bean class.

Primary Key Class

The name of the primary key class. It can be any Java class or primitive data type.

Step 7

Entity Bean Type

Use this page to specify generation options

Container Managed Persistence

If checked, the bean will have container-managed persistence.

Bean Managed Persistence

If checked, the bean will have bean-managed persistence.

Generate findAll() method in Home Interface

Adds a findAll() method to the home interface that returns all the rows in the data set.

Generate Header Comments

Adds JavaDoc header comments to the top of the class and interface files.

Code Style

You can choose to generate your entity beans in the current EJB 1.1 style, or, if you want to prepare for EJB 2.0, you can choose to use the EJB 2.0 style.

EJB 1.1 Style

Using this style, a single bean class is generated.

EJB 2.0 Style

Using this style, the bean class is defined as an abstract class and all the getter amdt setter methods are also defined as abstract. A second bean class extends this first bean class. It's named either <Bean class>CMP or <Bean class>BMP, depending on whether it's a bean with container-managed or bean-managed persistence. You add your business methods to this second class.