uCosminexus Application Server, Application Setup Guide
You map the fields of CMP2.x Entity Bean to a database table.
This section explains how to define the relationship (CMR) between two CMP2.x Entity Beans that define CMP.
The procedure of mapping CMP2.x and the database is as follows:
If there is a CMR relationship between the CMP2.x Entity Beans that define CMP, define the CMR between the CMP2.x Entity Beans.
EJB-JAR attribute file
Execute the following command to acquire an EJB-JAR attribute file:
cjgetappprop [server-name] [-nameserver provider-URL] -name J2EE application-name -type ejb -resname EJB-JAR-display-name -c path-of-the-EJB-JAR-attribute-file |
cjgetappprop MyServer -name adder -type ejb -resname adder -c C:\home\adder_ejb.xml
Execute the following command to apply the values of the EJB-JAR attribute file:
cjsetappprop [server-name] [-nameserver provider-URL] -name J2EE application-name -type ejb -resname EJB-JAR-display-name -c path-of-EJB-JAR-attribute-file |
cjsetappprop MyServer -name adder -type ejb -resname adder -c C:\home\adder_ejb.xml
The following table describes the property settings that define the relationship between two CMP2.x Entity Beans (<relationships> - <ejb-relation>):
| Items | Mandatory | Corresponding tags |
|---|---|---|
| Description | O | <description> |
| Relation definition name | Y | <ejb-relation-name> |
| Enterprise Bean(EJB1) information | Y | <ejb1> |
| Enterprise Bean(EJB2) information | Y | <ejb2> |
For details on the property settings, see 3.3.1 Contents of the EJB-JAR property file in the uCosminexus Application Server Application and Resource Definition Reference Guide.
For the Enterprise Bean (EJB1) information (<ejb1>) and Enterprise Bean (EJB2) information (<ejb2>), specify the items for the relationship between the Enterprise Bean on the setting side and the Enterprise Bean on the other side respectively.
| Items | Mandatory | Corresponding tags |
|---|---|---|
| Description | O | <description> |
| Role name of relationship | O | <ejb-relationship-role-name> |
| Multiplicity of setting side | Y | <multiplicity> |
| Setting of cascade delete | Y | <cascade-delete> |
| <ejb-name> of setting side | Y | <ejb-name> |
| Name of CMR field | Y | <cmr-field-name> |
| Type of CMR field | O | <cmr-field-type> |
For details on the property settings, see 3.3.1 Contents of the EJB-JAR property file in the uCosminexus Application Server Application and Resource Definition Reference Guide.
You map the fields of a CMP2.x Entity Bean to a table in the database.
For the attribute file to be edited, see (1) Attribute file to be edited in 9.6.2 Mapping of CMP1.x and database.
For details on acquiring the attribute file to be edited and setting the attributes, see (2) Acquiring the attribute file to be edited and setting the attributes in 9.6.2 Mapping CMP1.x and the database.
The following table describes the property settings for mapping the fields of a CMP2.x Entity Bean with a table in the database (<cmp-map>):
| Items | Mandatory | Corresponding tags |
|---|---|---|
| Display name of the resource adapter#1 | Y | <datasource-name> |
| Catalog name of the database | O | <catalog-name> |
| Schema name of the database | O | <schema-name> |
| Table name of the database | Y | <table-name> |
| Permission or prohibition of writing to the database | Y | <read-only-access> |
| Transaction isolation level#2 | O | <transaction-isolation> |
| Method of comparing the data by writing to the database | O | <concurrency-protection> |
| Information of mapping between the field and the table column#3 | Y | <field-impl> |
| Items | Corresponding tags |
|---|---|
| Field name of the EntityBean | <field-name> |
| Column name of the table | <column-name> |
For details on the property settings, see 3.5.1 Contents of the Entity Bean property file in the uCosminexus Application Server Application and Resource Definition Reference Guide.
You generate the SQL statement that is used when the finder or select method is executed.
Execute the following command to generate an SQL statement:
cjgencmpsql [server-name] -name J2EE application name |
cjgencmpsql MyServer -name App1
cjgencmpsql [server-name] -name J2EE application name -resname EJB-JAR-display-name/ Entity-Bean-display-name |
cjgencmpsql MyServer -name App1 -resname EjbJar1/Ejb1
For details on the cjgencmpsql command, see cjgencmpsql (Generating an SQL statement for the CMP2.x Entity Bean) in the uCosminexus Application Server Command Reference Guide.
This section describes the tables for CMR.
Note that in the explanation hereafter, the Entity Bean set in <ejb1> - <ejb-name> of EJB-JAR is called Bean1 and the Entity Bean set in <ejb2> - <ejb-name> is called Bean2.
In the EJB container, if there is a CMR relationship between the CMP2.x Entity Beans, a table is created in the database and it is used for maintaining the CMR status.
As shown in the following figure, the primary keys of two Entity Beans that are related are stored in the table for CMR:
Figure 9-1 Table for CMR (in the case of a one-to-one and a two-way relationship)
If an application that contains CMR is started, a table is generated for CMR. The table is generated in the schema that has the Bean1 table. This table is deleted when the application is stopped. For creating, deleting, and operating the tables, you use the SQL statement that is generated after database mapping when the application is customized.
If the server is stopped while the application is running, the table for CMR remains in the database. If the server is restarted while the application is running, the existence of the table for CMR in the database is checked. The following table describes the process of generating the table for CMR when an application and server are started:
Table 9-4 Process for generating the table for CMR when an application and server are started
| Status | Does a table with the same name as that of the table to be created exist in the database? | If a table with the same name exists, are the number of columns, name, and the JDBC type the same? | Operations | Message ID that is output |
|---|---|---|---|---|
| When starting#1 | No | Not applicable | Generate and use the table. | KDJE43007-I |
| Yes | Same or not the same | Startup is suspended.#2 | KDJE43003-E | |
| When starting the J2EE server | No | Not applicable | Startup is suspended.#3 | KDJE43008-E |
| Yes | Same | When starting, assume that the table has been created for CMR and use it. | KDJE43006-I | |
| Not the same | Startup is suspended.#3 | KDJE43008-E |
The name of the table for CMR is as follows:
If the name decided by this method is of 29 characters or more, it will be truncated to 28 characters. If the name that is truncated to 28 characters matches with a table name already existing in the database or if it overlaps with the name of the table for another CMR in the same EJB-JAR, then it is differentiated by adding a number from 0 to 99 at the end.
When an application that contains CMR is started, if a failure occurs while the J2EE server was stopped for maintenance and then restarted, the J2EE server may not restart with the running application that contains CMR. After resolving the error, even if you try to restart the application that contains CMR, then, as described in Table 9-4, the application cannot be started if there is a table in the database with the same name as that of the table to be created (in order to avoid sharing of tables between the applications).
If the process of generating an SQL statement is executed again, an SQL statement that uses a new table name for CMR, is generated, and you can start the application by using the new table for CMR. If you want to continue the relation that was being used before stopping the J2EE server, you must start the application by using the table that is remaining in the database.
The ejbserver.ejb.cmp20.cmr.use.existing_table key in the usrconf.properties file is an option for restoring the relationship information that was being used until the start up of the application failed. If true is specified in this key, you can start the application by using the table that already exists in the database. If nothing is specified or if false is specified in this key, execute the operations described in Table 9-4. The procedure for using the existing table by using this option is as follows:
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.