deploytool Tips for Entity Beans With Container-Managed Persistence
Chapter 2 covered the basic steps for building and packaging enterprise beans. This section highlights the tasks in
deploytoolthat are needed for entity beans with container-managed persistence. The examples referenced in this section are from A Guided Tour of the RosterApp Settings.
Specifying the Bean's Type
In the New Enterprise Bean wizard, specify the bean's type and persistent management.
- In the Edit Contents dialog box, add all of the classes required by the entity bean and by its related beans.
- In the General dialog box, select the Entity radio button.
- In the General dialog box, specify the local interfaces of the entity bean. (If the bean also has remote interfaces, specify them as well.)
- In the Entity Settings dialog box, select the radio button for Container-Managed Persistence (2.0). You may skip the other settings in this dialog box and enter them later in the Entity tab.
Selecting the Persistent Fields and Abstract Schema Name
In the Entity tab, enter the field information and the abstract schema name.
- In the Fields To Be Persisted list, select the fields that will be saved in the database. The names of the persistent fields are determined by the access methods defined in the entity bean code.
- Enter values in the Primary Key Class and Primary Key Field Name fields. The primary key uniquely identifies the entity bean.
- In the Abstract Schema Name field, enter a name that represents the entity bean. This name will be referenced in the EJB QL queries.
An example is shown in the section Entity Tab (PlayerEJB).
Defining EJB QL Queries for Finder and Select Methods
You specify these settings in the Finder/Select Methods dialog box.
- To open the Finder/Select Methods dialog box, go to the Entity tab and click Finder/Select Methods.
- To display a set of finder or select methods, click one of the radio buttons under the Show label.
- To specify an EJB QL query, choose the name of the finder or select method from the Method list and then enter the query in the field labeled EJB QL Query.
An example is shown in the section Finder/Select Methods Dialog Box (PlayerEJB).
Generating SQL and Specifying Table Creation
deploytool, the various Deployment Settings dialog boxes enable you to enter information needed by the server at runtime. These settings are specific to the J2EE SDK implementation.
- To open the Deployment Settings dialog box, go to the Entity tab and click Deployment Settings.
- With container-managed persistence, the container can automatically create or delete the database table used by the entity bean. If you've loaded test data into the table, you may want to deselect the checkboxes in the Database Table box.
- To translate the EJB QL queries into SQL
SELECTstatements, click Generate Default SQL. If this button is disabled, you must first specify the database settings.
An example is shown in the section Entity Deployment Settings Dialog Box (PlayerEJB).
Specifying the Database JNDI Name, User Name, and Password
You specify these settings in the Database Settings dialog box.
- To open the Database Settings dialog box, go to the Entity tab and click Deployment Settings. In the Deployment Settings dialog box, click Database Settings.
- Enter a value in the Database JNDI Name field. The examples in this book use the
- The Cloudscape database shipped with the J2EE SDK does not require a user name or password. So, if your bean connects to the Cloudscape database, you may leave the User Name and Password fields blank. To connect to other types of databases, you may need to enter values into these fields.
An example is shown in the section Database Deployment Settings Dialog Box (PlayerEJB).
The Relationships tab enables you to define relationships between entity beans that reside in the same EJB JAR file.
- Before you create a relationship between two entity beans, you must first create both beans with the New Enterprise Bean wizard.
- To display the Relationships tab, select the EJB JAR in the tree view and then select the Relationships tab.
- To add or edit a relationship, go the Relationships tab and click the appropriate button.
- The Add (or Edit) Relationship dialog box appears. (The Add Relationship and Edit Relationship dialog boxes are identical.)
An example is shown in the section Edit Relationship Dialog Box (TeamJAR).