Using the EJB Designer and CMP 2.0 properties

The DDEditor's implementation of the EJB Designer is primarily to facilitate the (O/R) mapping of CMP 2.0 entity beans' persistence schemas to a database, and for setting Borland-specific entity bean CMP properties for deployment. Many properties are disabled in the DDEditor's implementation of the EJB Designer as they require code change and must be changed in the source.

To use the EJB Designer effectively, you should have a schema already imported into the DDEditor in order to edit the CMP 2.0 properties. If you do not have it set up already, or do not have the vendor-specific XML imported, you will have to create and edit the table properties manually.

For information on the full implementation of the EJB Designer, refer to Borland JBuilder documentation, Enterprise Application Developer's Guide.

CMP properties you can edit are:

Table properties

Methods

Bean properties

Entity CMP properties

Session bean

EJB Designer and CMP 2.0 general information

The Borland Enterprise Server's EJB Container implements both container-managed persistence (CMP) for EJBs implementing either the EJB 1.1 and/or EJB 2.0 specifications. The bean provider designs persistence schemas for entity beans, determines the methods for accessing container-managed fields and relationships, and defines these in the beans' deployment descriptors. The deployer then maps the persistence schema to the database and creates any other necessary classes for the beans' maintenance.

Container-created tables

You can instruct the Borland EJB Container to automatically create tables for container-managed entities based on the entity's container-managed fields, which are defined in the entity bean deployment descriptors. Because table creation and data type mappings vary among vendors, you must specify the JDBC database dialect in the deployment descriptor to the Container. For all databases (except JDataStore), if you specify the dialect, the Container automatically creates tables for container-managed entities for you. The Container will not create these tables unless you specify the dialect.

Table mapping for CMP 2.0 is accomplished using the Borland-specific ejb-borland.xml deployment descriptor. This descriptor is a companion to the ejb-jar.xml descriptor described in the EJB 2.0 specification. Borland uses the XML tag <cmp2-info> for enclosing table mapping.

Editing entity CMP properties

To edit entity CMP properties:

  1. Click on the entity bean representation in the EJB Designer.
  2. In the properties panel click the Properties button under CMP properties.
  3. Edit any properties you wish and click OK.

    For more information on the CMP properties; descriptions of the entities, data types, default values, table and column properties, and property descriptions, refer to the Borland Enterprise Server Developer's Guide, "Using BES Properties for CMP 2.x".

Finder methods in the EJB Designer

Finder methods allow the client to access the results of an EJB QL query. Finder methods for a CMP 2.0 entity bean must have an EJB query language (QL) query defined in its deployment descriptor. An EJB QL query is a string that must contain a SELECT clause and a FROM clause and may include a WHERE clause. You can use the EJB Designer to edit a finder method's QL string. You can not set finder methods in the DDEditor's EJB Designer, as this should be done in your in your source code.

To edit a bean's finder method's QL string, click on the finder method in the bean's representation in the EJB Designer and edit the string in the Query box.

Editing finder methods

[Picture]

Table Reference Editor

You can create relationships between EJB 2.0 entity beans. For example, if you have an EMPLOYEE table, you might want to create a relationship that reflects which employees are assigned to which project(s). Relationships are created when entity beans are created. The EJB Designer allows you to edit table relationships.

To create relationships between EJB 2.0 entity beans using the EJB Designer, refer to the Borland JBuilder Enterprise Application Developer's Guide documentation.

By default, the relationships are created by looking for columns (or fields) with the same name in the two tables you are connecting. Often, the two tables won't have a common column name. You must therefore specify how the relationship is created.

Using the Table Reference Editor to specify table relationships

If two tables do not have common column names, you must connect the columns you want to use to create the relationship by drawing a line. For example, if the EMPLOYEE table has a column called EMP_NO, and the EMPLOYEE_PROJECT table has a column called PROJ_ID, you can draw a line between the two columns to create the relationship.

Note: The links drawn in represent the foreign key relationships between tables.

To create a table relationship:

  1. In the DDEditor's EJB Designer, click on the name of entity bean representation in the EJB Designer.
  2. In the Bean properties panel, click the Add button in the table references section.

    The entity bean's table and columns should be present in the left menu.

  3. Select a table from the drop-down list on the right that you want the selected entity bean's table to reference.
  4. Click and drag to draw links between the columns of the table on the left and the table on the right.

    Once you've created the relationship(s), click OK.

    Specifying table references

    [Picture]

Many-to-many relationships

For many-to-many relationships you need a third table to make the connection between two tables. For example, you might have an EMPLOYEE table that includes a column named EMP_NO. You might also have a PROJECT table with a column named PROJ_ID. By themselves the two tables may not have any columns you can use to create a relationship directly. If you have an EMPLOYEE-PROJECT table that consists of two columns, EMP_NO and PROJ_ID, you can create a relationship between the EMPLOYEE and PROJECT tables. In this case, you would use the "Add Cross Table" function in the Table Reference Editor.

To use the Add Cross Table function to create a many-to-many relationship:

  1. In the DDEditor's EJB Designer, click on the name of entity bean representation in the EJB Designer.
  2. In the Bean properties panel, click the Add button in the table references section.

    The entity bean's table and columns should be present in the left menu.

  3. Select a table from the drop-down list on the right that you want the selected entity bean's table to reference.
  4. To add a cross table (an intermediate table used to related two unrelated tables), click the Add Cross Table button.
  5. From the drop-down list that appears between the two tables, select the new table that contains the columns to make the connection between the two.
  6. Click and drag between the columns to make the appropriate connections.

    Using a cross table for many-to-many relationships [Picture]

  7. Click OK when you are done with the cross table.

    A new field will appear in the Bean properties panel of your referenced bean in the Table References window.

    This will appear in the Vendor XML tab as a Borland-specific descriptor element <table-ref> using the element(s) left-table, <right-table> and <cross-table>.