8.11. JOnAS Database Mapping (Specific Deployment Descriptor)

You can specify the mapping to the database of Entity Beans and their relationships in the JOnAS-specific deployment descriptor, in jonas-entity elements, and in jonas-ejb-relation elements. Since JOnAS is able to generate the database mapping, all the elements of the JOnAS-specific deployment descriptor defined in this section (which are sub-elements of jonas-entity or jonas-ejb-relation) are optional, except those for specifying the datasource and the initialization mode (that is, the jndi-name of jdbc-mapping and cleanup). The default values of these mapping elements, provided in this section, define the JOnAS-generated database mapping.

8.11.1. Specifying and Initializing the Database

To specify the database within which a CMP 2.0 Entity Bean is stored, use the jndi-name element of the jdbc-mapping. This is the JNDI name of the DataSource representing the database storing the Entity Bean.

<jdbc-mapping>
  <jndi-name>jdbc_1</jndi-name>
</jdbc-mapping>

For a CMP 2.0 Entity Bean, the JOnAS-specific deployment descriptor contains an additional element, cleanup, to be specified before the jdbc-mapping element. The cleanup element can have one of the following values:

removedata

At bean loading time, delete the content of the tables storing the bean data

removeall

At bean loading time, drop the tables storing the bean data (if they exist) and re-create them

none

Do nothing

create

Default value (if the element is not specified). At bean loading time, create the tables for storing the bean data (if they do not exist).

It may be useful for testing purposes to delete the database data each time a bean is loaded. To do this, the part of the JOnAS-specific deployment descriptor related to the Entity Bean may look like the following:

<cleanup>removedata</cleanup>
<jdbc-mapping>
  <jndi-name>jdbc_1</jndi-name>
</jdbc-mapping>

8.11.2. CMP fields mapping

Mapping CMP fields in CMP2.0 is similar to that of CMP1.1, but in CMP2.0 it is also possible to specify the SQL type of a column. Usually this SQL type is used if JOnAS creates the table (the create value of the cleanup element) and if the JORM SQL type is not appropriate.

8.11.2.1. Standard Deployment Descriptor

.....
<entity>
  <ejb-name>A</ejb-name>
  .....
  <cmp-field>
    <field-name>idA</field-name>
  </cmp-field>
  <cmp-field>
    <field-name>f</field-name>
  </cmp-field>
.....
</entity>
.....

8.11.2.2. Database Mapping

t_A 
c_idAc_f
......

8.11.2.3. JOnAS Deployment Descriptor

.....
<jonas-entity>
  <ejb-name>A</ejb-name>
  .....
  <jdbc-mapping>
    <jndi-name>jdbc_1</jndi-name>
    <jdbc-table-name>t_A</jdbc-table-name>
    <cmp-field-jdbc-mapping>
      <field-name>idA</field-name>
      <jdbc-field-name>c_idA</jdbc-field-name>
    </cmp-field-jdbc-mapping>
    <cmp-field-jdbc-mapping>
      <field-name>f</field-name>
      <jdbc-field-name>c_f</jdbc-field-name>
      <sql-type>varchar(40)</sql-type>
    </cmp-field-jdbc-mapping>
  </jdbc-mapping>
  .....
</jonas-entity>
.....
jndi-nameMandatory
jdbc-table-nameOptional. Default value is the upper-case CMP2 abstract-schema-name, or the CMP1 EJB-name, suffixed by "_".
cmp-field-jdbc-mappingOptional.
jdbc-field-nameOptional. Default value is the field-name suffixed by "_". "idA_" and "f_" in the example.
sql-typeOptional. Default value defined by JORM.

Table 8-1. CMP fields mapping: Default values

8.11.3. CMR fields mapping to primary-key-fields (simple pk)

8.11.3.1. 1-1 unidirectional relationships

8.11.3.1.1. Standard Deployment Descriptor

.....
<entity>
  <ejb-name>A</ejb-name>
  .....
  <cmp-field>
    <field-name>idA</field-name>
  </cmp-field>
  <primkey-field>idA</primkey-field>
  .....
</entity>
.....
<entity>
  <ejb-name>B</ejb-name>
  .....
  <cmp-field>
    <field-name>idB</field-name>
  </cmp-field>
  <primkey-field>idB</primkey-field>
  .....
</entity>
.....
<relationships>
  <ejb-relation>
    <ejb-relation-name>a-b</ejb-relation-name>
    <ejb-relationship-role>
      <!-- A => B -->
            <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
      <multiplicity>One</multiplicity>
      <relationship-role-source>
        <ejb-name>A</ejb-name>
      </relationship-role-source>
      <cmr-field>
        <cmr-field-name>b</cmr-field-name>
      </cmr-field>
    </ejb-relationship-role>
    <ejb-relationship-role>
      <!-- B => A -->
      <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
      <multiplicity>One</multiplicity>
      <relationship-role-source>
        <ejb-name>B</ejb-name>
      </relationship-role-source>
    </ejb-relationship-role>
  </ejb-relation>
</relationships>
.....

8.11.3.1.2. Database Mapping

t_A 
c_idAcfk_idB
......

t_B
c_idB
...

There is a foreign key in the table of the bean that owns the CMR field.

8.11.3.1.3. JOnAS Deployment Descriptor

.....
<jonas-entity>
  <ejb-name>A</ejb-name>
  .....
  <jdbc-mapping>
    <jndi-name>jdbc_1</jndi-name>
    <jdbc-table-name>t_A/jdbc-table-name>
    <cmp-field-jdbc-mapping>
      <field-name>idA</field-name>
      <jdbc-field-name>c_idA</jdbc-field-name>
    </cmp-field-jdbc-mapping>
  </jdbc-mapping>
  .....
</jonas-entity>
.....
<jonas-entity>
  <ejb-name>B</ejb-name>
  .....
  <jdbc-mapping>
    <jndi-name>jdbc_1</jndi-name>
    <jdbc-table-name>t_B/jdbc-table-name>
    <cmp-field-jdbc-mapping>
      <field-name>idB</field-name>
      <jdbc-field-name>c_idB</jdbc-field-name>
    </cmp-field-jdbc-mapping>
  </jdbc-mapping>
  .....
</jonas-entity>
.....
<jonas-ejb-relation>
  <ejb-relation-name>a-b</ejb-relation-name>
  <jonas-ejb-relationship-role>
    <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_idb</foreign-key-jdbc-name>
    </foreign-key-jdbc-mapping>
  </jonas-ejb-relationship-role>
</jonas-ejb-relation>
.....

foreign-key-jdbc-name is the column name of the foreign key in the table of the source bean of the relationship-role.

In this example, where the destination bean has a primary-key-field, it is possible to deduce that this foreign-key-jdbc-name column is to be associated with the column of this primary-key-field in the table of the destination bean.

jonas-ejb-relationOptional
foreign-key-jdbc-nameOptional. Default value is the abstract-schema-name of the destination bean, suffixed by "_" and by its primary-key-field. B_idb in the example.

Table 8-2. 1-1 unidirectional relationships: Default values

8.11.3.2. 1-1 bidirectional relationships

In contrast to 1-1 unidirectional relationships, there is a CMR field in both of the beans, thus making two types of mapping possible.

8.11.3.2.1. Standard Deployment Descriptor

.....
<relationships>
  <ejb-relation>
    <ejb-relation-name>a-b</ejb-relation-name>
    <ejb-relationship-role>
      <!-- A => B -->
            <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
      <multiplicity>One</multiplicity>
      <relationship-role-source>
        <ejb-name>A</ejb-name>
      </relationship-role-source>
      <cmr-field>
        <cmr-field-name>b</cmr-field-name>
      </cmr-field>
    </ejb-relationship-role>
    <ejb-relationship-role>
      <!-- B => A -->
      <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
      <multiplicity>One</multiplicity>
      <relationship-role-source>
        <ejb-name>B</ejb-name>
      </relationship-role-source>
      <cmr-field>
        <cmr-field-name>a</cmr-field-name>
      </cmr-field>
    </ejb-relationship-role>
  </ejb-relation>
</relationships>
.....

8.11.3.2.2. Database Mapping

Two mappings are possible. One of the tables may hold a foreign key.

Case 1:

t_A 
c_idAcfk_idB
......

t_B
c_idB
...

Case 2:

t_A 
c_idA 
... 

t_B 
c_idBcfk_idA
......

8.11.3.2.3. JOnAS Deployment Descriptor

Case 1:

    .....
    <jonas-ejb-relation>
      <ejb-relation-name>a-b</ejb-relation-name>
      <jonas-ejb-relationship-role>
        <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
        <foreign-key-jdbc-mapping>
          <foreign-key-jdbc-name>cfk_idb</foreign-key-jdbc-name>
        </foreign-key-jdbc-mapping>
      </jonas-ejb-relationship-role>
    </jonas-ejb-relation>
    .....
    

Case 2:

    .....
    <jonas-ejb-relation>
      <ejb-relation-name>a-b</ejb-relation-name>
      <jonas-ejb-relationship-role>
        <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
        <foreign-key-jdbc-mapping>
          <foreign-key-jdbc-name>cfk_ida</foreign-key-jdbc-name>
        </foreign-key-jdbc-mapping>
      </jonas-ejb-relationship-role>
    </jonas-ejb-relation>
    .....
    

For the default mapping, the foreign key is in the table of the source bean of the first ejb-relationship-role of the ejb-relation. In the example, the default mapping corresponds to case 1, since the ejb-relationship-role a2b is the first defined in the ejb-relation a-b. Then, the default values are similar to those of the 1-1 unidirectional relationship.

8.11.3.3. 1-N unidirectional relationships

8.11.3.3.1. Standard Deployment Descriptor

    .....
<relationships>
  <ejb-relation>
    <ejb-relation-name>a-b</ejb-relation-name>
    <ejb-relationship-role>
      <!-- A => B -->
            <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
      <multiplicity>One</multiplicity>
      <relationship-role-source>
        <ejb-name>A</ejb-name>
      </relationship-role-source>
      <cmr-field>
        <cmr-field-name>b</cmr-field-name>
        <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
    </ejb-relationship-role>
    <ejb-relationship-role>
      <!-- B => A -->
      <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
      <multiplicity>Many</multiplicity>
      <relationship-role-source>
        <ejb-name>B</ejb-name>
      </relationship-role-source>
    </ejb-relationship-role>
  </ejb-relation>
</relationships>
.....

8.11.3.3.2. Database Mapping

t_A 
c_idA 
... 

t_B 
c_idBcfk_idA
......

In this case, the foreign key must be in the table of the bean which is on the "many" side of the relationship (that is, in the table of the source bean of the relationship role with multiplicity many), t_B.

8.11.3.3.3. JOnAS Deployment Descriptor

.....
<jonas-ejb-relation>
  <ejb-relation-name>a-b</ejb-relation-name>
  <jonas-ejb-relationship-role>
    <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_ida</foreign-key-jdbc-name>
    </foreign-key-jdbc-mapping>
  </jonas-ejb-relationship-role>
</jonas-ejb-relation>
.....
jonas-ejb-relationOptional
foreign-key-jdbc-nameOptional. Default value is the abstract-schema-name of the destination bean of the "one" side of the relationship (that is, the source bean of the relationship role with multiplicity one) suffixed by "_" and by its primary-key-field. A_ida in the example.

Table 8-3. 1-N unidirectional relationships: Default values

8.11.3.4. 1-N bidirectional relationships

Similar to 1-N unidirectional relationships, but with a CMR field in each bean.

8.11.3.4.1. Standard Deployment Descriptor

.....
<relationships>
  <ejb-relation>
    <ejb-relation-name>a-b</ejb-relation-name>
    <ejb-relationship-role>
      <!-- A => B -->
            <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
      <multiplicity>One</multiplicity>
      <relationship-role-source>
        <ejb-name>A</ejb-name>
      </relationship-role-source>
      <cmr-field>
        <cmr-field-name>b</cmr-field-name>
        <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
    </ejb-relationship-role>
    <ejb-relationship-role>
      <!-- B => A -->
      <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
      <multiplicity>Many</multiplicity>
      <relationship-role-source>
        <ejb-name>B</ejb-name>
      </relationship-role-source>
      <cmr-field>
        <cmr-field-name>a</cmr-field-name>
      </cmr-field>
    </ejb-relationship-role>
  </ejb-relation>
</relationships>
.....

8.11.3.4.2. Database Mapping

t_A 
c_idA 
... 

t_B 
c_idBcfk_idA
......

In this case, the foreign key must be in the table of the bean that is on the "many" side of the relationship (that is, in the table of the source bean of the relationship role with multiplicity many), t_B.

8.11.3.4.3. JOnAS Deployment Descriptor

.....
<jonas-ejb-relation>
  <ejb-relation-name>a-b</ejb-relation-name>
  <jonas-ejb-relationship-role>
    <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_ida</foreign-key-jdbc-name>
    </foreign-key-jdbc-mapping>
  </jonas-ejb-relationship-role>
</jonas-ejb-relation>
.....
jonas-ejb-relationOptional
foreign-key-jdbc-nameOptional. Default value is the abstract-schema-name of the destination bean of the "one" side of the relationship (that is, the source bean of the relationship role with multiplicity one), suffixed by "_" and its primary-key-field. A_ida in the example.

Table 8-4. 1-N bidirectional relationships: Default values

8.11.3.5. N-1 Unidirectional Relationships

Similar to 1-N unidirectional relationships, but the CMR field is defined on the "many" side of the relationship, that is, on the (source bean of the) relationship role with multiplicity "many."

8.11.3.5.1. Standard Deployment Descriptor

.....
<relationships>
  <ejb-relation>
    <ejb-relation-name>a-b</ejb-relation-name>
    <ejb-relationship-role>
      <!-- A => B -->
            <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
      <multiplicity>Many</multiplicity>
      <relationship-role-source>
        <ejb-name>A</ejb-name>
      </relationship-role-source>
      <cmr-field>
        <cmr-field-name>b</cmr-field-name>
      </cmr-field>
    </ejb-relationship-role>
    <ejb-relationship-role>
      <!-- B => A -->
      <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
      <multiplicity>One</multiplicity>
      <relationship-role-source>
        <ejb-name>B</ejb-name>
      </relationship-role-source>
    </ejb-relationship-role>
  </ejb-relation>
</relationships>
.....

8.11.3.5.2. Database Mapping

t_A 
c_idAcfk_idB
......

t_B
c_idB
...

In this case, the foreign key must be in the table of the bean which is on the "many" side of the relationship (that is, in table of the source bean of the relationship role with multiplicity many), t_A.

8.11.3.5.3. JOnAS Deployment Descriptor

.....
<jonas-ejb-relation>
  <ejb-relation-name>a-b</ejb-relation-name>
  <jonas-ejb-relationship-role>
    <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_idb</foreign-key-jdbc-name>
    </foreign-key-jdbc-mapping>
  </jonas-ejb-relationship-role>
</jonas-ejb-relation>
.....
jonas-ejb-relationOptional
foreign-key-jdbc-nameOptional. Default value is the abstract-schema-name of the destination bean of the "one" side of the relationship (that is, the source bean of the relationship role with multiplicity one) suffixed by "_" and by its primary-key-field. B_idb in the example.

Table 8-5. N-1 unidirectional relationships: Default values

8.11.3.6. N-M Unidirectional Relationships

8.11.3.6.1. Standard Deployment Descriptor

.....
<relationships>
  <ejb-relation>
    <ejb-relation-name>a-b</ejb-relation-name>
    <ejb-relationship-role>
      <!-- A => B -->
            <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
      <multiplicity>Many</multiplicity>
      <relationship-role-source>
        <ejb-name>A</ejb-name>
      </relationship-role-source>
      <cmr-field>
        <cmr-field-name>b</cmr-field-name>
        <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
    </ejb-relationship-role>
    <ejb-relationship-role>
      <!-- B => A -->
      <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
      <multiplicity>Many</multiplicity>
      <relationship-role-source>
        <ejb-name>B</ejb-name>
      </relationship-role-source>
    </ejb-relationship-role>
  </ejb-relation>
</relationships>
.....

8.11.3.6.2. Database Mapping

t_A 
c_idA 
... 

t_B
c_idB
...

tJoin_AB 
cfk_idAcfk_idB
......

In this case, there is a join table composed of the foreign keys of each Entity Bean table.

8.11.3.6.3. JOnAS Deployment Descriptor

.....
<jonas-ejb-relation>
  <ejb-relation-name>a-b</ejb-relation-name>
  <jdbc-table-name>tJoin_AB</jdbc-table-name>
  <jonas-ejb-relationship-role>
    <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_idb</foreign-key-jdbc-name>
    </foreign-key-jdbc-mapping>
  </jonas-ejb-relationship-role>
  <jonas-ejb-relationship-role>
    <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_ida</foreign-key-jdbc-name>
    </foreign-key-jdbc-mapping>
  </jonas-ejb-relationship-role>
</jonas-ejb-relation>
.....
jonas-ejb-relationOptional
jdbc-table-nameOptional. Default value is built from the abstract-schema-names of the beans, separated by _. A_B in the example.
foreign-key-jdbc-nameOptional. Default value is the abstract-schema-name of the destination bean, suffixed by "_" and by its primary-key-field. B_idb and A_ida in the example.

Table 8-6. N-M unidirectional relationships: Default values

8.11.3.7. N-M Bidirectional Relationships

Similar to N-M unidirectional relationships, but a CMR field is defined for each bean.

8.11.3.7.1. Standard Deployment Descriptor

.....
<relationships>
  <ejb-relation>
    <ejb-relation-name>a-b</ejb-relation-name>
    <ejb-relationship-role>
      <!-- A => B -->
            <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
      <multiplicity>Many</multiplicity>
      <relationship-role-source>
        <ejb-name>A</ejb-name>
      </relationship-role-source>
      <cmr-field>
        <cmr-field-name>b</cmr-field-name>
        <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
    </ejb-relationship-role>
    <ejb-relationship-role>
      <!-- B => A -->
      <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
      <multiplicity>Many</multiplicity>
      <relationship-role-source>
        <ejb-name>B</ejb-name>
      </relationship-role-source>
      <cmr-field>
        <cmr-field-name>a</cmr-field-name>
        <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
    </ejb-relationship-role>
  </ejb-relation>
</relationships>
.....

8.11.3.7.2. Database Mapping

t_A
c_idA
...

t_B
c_idB
...

tJoin_AB 
cfk_idAcfk_idB
......

In this case, there is a join table composed of the foreign keys of each Entity Bean table.

8.11.3.7.3. JOnAS Deployment Descriptor

.....
<jonas-ejb-relation>
  <ejb-relation-name>a-b</ejb-relation-name>
  <jdbc-table-name>tJoin_AB</jdbc-table-name>
  <jonas-ejb-relationship-role>
    <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_idb</foreign-key-jdbc-name>
    </foreign-key-jdbc-mapping>
  </jonas-ejb-relationship-role>
  <jonas-ejb-relationship-role>
    <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_ida</foreign-key-jdbc-name>
    </foreign-key-jdbc-mapping>
  </jonas-ejb-relationship-role>
</jonas-ejb-relation>
.....
jonas-ejb-relationOptional
jdbc-table-nameOptional. Default value is built from the abstract-schema-names of the beans, separated by _. A_B in the example.
foreign-key-jdbc-nameOptional. Default value is the abstract-schema-name of the destination bean, suffixed by "_" and by its primary-key-field. B_idb and A_ida in the example.

Table 8-7. CMR fields mapping to primary-key-fields: Default values

8.11.4. CMR fields Mapping to Composite Primary-Keys

In the case of composite primary keys, the database mapping should provide the capability to specify which column of a foreign key corresponds to which column of the primary key. This is the only difference between relationships based on simple primary keys. For this reason, not all types of relationship are illustrated below.

8.11.4.1. 1-1 Bidirectional Relationships

8.11.4.1.1. Standard Deployment Descriptor

.....
<entity>
  <ejb-name>A</ejb-name>
  .....
  <prim-key-class>p.PkA</prim-key-class>
  .....
  <cmp-field>
    <field-name>id1A</field-name>
  </cmp-field>
  <cmp-field>
    <field-name>id2A</field-name>
  </cmp-field>
  .....
</entity>
.....
<entity>
  <ejb-name>B</ejb-name>
  .....
  <prim-key-class>p.PkB</prim-key-class>
  .....
  <cmp-field>
    <field-name>id1B</field-name>
  </cmp-field>
  <cmp-field>
    <field-name>id2B</field-name>
  </cmp-field>
  .....
</entity>
.....
<relationships>
  <ejb-relation>
    <ejb-relation-name>a-b</ejb-relation-name>
    <ejb-relationship-role>
      <!-- A => B -->
            <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
      <multiplicity>One</multiplicity>
      <relationship-role-source>
        <ejb-name>A</ejb-name>
      </relationship-role-source>
      <cmr-field>
        <cmr-field-name>b</cmr-field-name>
      </cmr-field>
    </ejb-relationship-role>
    <ejb-relationship-role>
      <!-- B => A -->
      <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
      <multiplicity>One</multiplicity>
      <relationship-role-source>
        <ejb-name>B</ejb-name>
      </relationship-role-source>
      <cmr-field>
        <cmr-field-name>a</cmr-field-name>
      </cmr-field>
    </ejb-relationship-role>
  </ejb-relation>
</relationships>
.....

8.11.4.1.2. Database Mapping

Two mappings are possible, one or another of the tables may hold the foreign key.

Case 1:

t_A   
c_id1Ac_id2Acfk_id1Bcfk_id2B
............

t_B 
c_id1Bc_id2B
......

Case 2:

t_A 
c_id1Ac_id2A
......

t_B   
c_id1Bc_id2Bcfk_id1Acfk_id2A
............

8.11.4.1.3. JOnAS Deployment Descriptor

Case 1:

.....
<jonas-ejb-relation>
  <ejb-relation-name>a-b</ejb-relation-name>
  <jonas-ejb-relationship-role>
    <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_id1b</foreign-key-jdbc-name>
      <key-jdbc-name>c_id1b</key-jdbc-name>
    </foreign-key-jdbc-mapping>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_id2b</foreign-key-jdbc-name>
      <key-jdbc-name>c_id2b</key-jdbc-name>
    </foreign-key-jdbc-mapping>
  </jonas-ejb-relationship-role>
</jonas-ejb-relation>
.....

Case 2:

.....
<jonas-ejb-relation>
  <ejb-relation-name>a-b</ejb-relation-name>
  <jonas-ejb-relationship-role>
    <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_id1a</foreign-key-jdbc-name>
      <key-jdbc-name>c_id1a</key-jdbc-name>
    </foreign-key-jdbc-mapping>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_id2a</foreign-key-jdbc-name>
      <key-jdbc-name>c_id2a</key-jdbc-name>
    </foreign-key-jdbc-mapping>
  </jonas-ejb-relationship-role>
</jonas-ejb-relation>
.....

For the default mapping (values), the foreign key is in the table of the source bean of the first ejb-relationship-role of the ejb-relation. In the example, the default mapping corresponds to case 1, since the ejb-relationship-role a2b is the first defined in the ejb-relation a-b.

8.11.4.2. N-M Unidirectional Relationships

8.11.4.2.1. Standard Deployment Descriptor

.....
<entity>
  <ejb-name>A</ejb-name>
  .....
  <cmp-field>
    <field-name>id1A</field-name>
  </cmp-field>
  <cmp-field>
    <field-name>id2A</field-name>
  </cmp-field>
  .....
</entity>
.....
<entity>
  <ejb-name>B</ejb-name>
  .....
  <cmp-field>
    <field-name>id1B</field-name>
  </cmp-field>
  <cmp-field>
    <field-name>id2B</field-name>
  </cmp-field>
  .....
</entity>
.....
<relationships>
  <ejb-relation>
    <ejb-relation-name>a-b</ejb-relation-name>
    <ejb-relationship-role>
      <!-- A => B -->
            <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
      <multiplicity>Many</multiplicity>
      <relationship-role-source>
        <ejb-name>A</ejb-name>
      </relationship-role-source>
      <cmr-field>
        <cmr-field-name>b</cmr-field-name>
        <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
    </ejb-relationship-role>
    <ejb-relationship-role>
      <!-- B => A -->
      <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
      <multiplicity>Many</multiplicity>
      <relationship-role-source>
        <ejb-name>B</ejb-name>
      </relationship-role-source>
    </ejb-relationship-role>
  </ejb-relation>
</relationships>
.....

8.11.4.2.2. Database Mapping

t_A 
c_id1Ac_id2A
......

t_B 
c_id1Bc_id2B
......

tJoin_AB   
cfk_id1Acfk_id2Acfk_id1Bcfk_id2B
............

In this case, there is a join table composed of the foreign keys of each Entity Bean table.

8.11.4.2.3. JOnAS Deployment Descriptor

.....
<jonas-ejb-relation>
  <ejb-relation-name>a-b</ejb-relation-name>
  <jdbc-table-name>tJoin_AB</jdbc-table-name>
  <jonas-ejb-relationship-role>
    <ejb-relationship-role-name>a2b</ejb-relationship-role-name>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_id1b</foreign-key-jdbc-name>
      <key-jdbc-name>c_id1b</key-jdbc-name>
    </foreign-key-jdbc-mapping>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_id2b</foreign-key-jdbc-name>
      <key-jdbc-name>c_id2b</key-jdbc-name>
    </foreign-key-jdbc-mapping>
  </jonas-ejb-relationship-role>
  <jonas-ejb-relationship-role>
    <ejb-relationship-role-name>b2a</ejb-relationship-role-name>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_id1a</foreign-key-jdbc-name>
      <key-jdbc-name>c_id1a</key-jdbc-name>
    </foreign-key-jdbc-mapping>
    <foreign-key-jdbc-mapping>
      <foreign-key-jdbc-name>cfk_id2a</foreign-key-jdbc-name>
      <key-jdbc-name>c_id2a</key-jdbc-name>
    </foreign-key-jdbc-mapping>
  </jonas-ejb-relationship-role>
</jonas-ejb-relation>
.....