Migrating JBoss specific descriptors

You have to integrate both jboss.xml and jaws.xml in the JOnAS specific deployment descriptor named jonas-ejb-jar.xml. This file contains, for each bean, the JNDI name of the home object, EJB references, datasource, JMS administered objects and the information about the mapping of the bean to the database. Note that only from JOnAS 3.2, the JNDI configuration support hierarchical name espace, so if you used JNDI hierarchical names in Jboss.xml you have to change them for any JOnAS version lower than 3.2. JBoss disposes different JNDI tags (<jndi-name>, <local-jndi-name>) for the remote and local objects, and JOnAS has only one JNDI tag (<jndi-name>) for both remote and local objects, so if you defined some local object in jboss.xml, don't forget to change them with the unique JOnAS JNDI tag.

Migrating jboss.xml

The jboss.xml contains the JNDI name of the beans and of the datasource. You will have to move this to the jonas-ejb-jar.xml file.

Session Bean

This is the jboss.xml file for SB_BrowseRegion:

<jboss>
    <session>
      <ejb-name>SB_BrowseRegions</ejb-name>
      <jndi-name>SB_BrowseRegionsHome</jndi-name>
      <resource-ref>
        <res-ref-name>jdbc/rubis</res-ref-name>
        <resource-name>rubis</resource-name>
      </resource-ref>
    </session>
</jboss>
         

The equivalent jonas-ejb-jar.xml file looks like:

<jonas-ejb-jar>
    <jonas-session>
        <ejb-name>SB_BrowseRegions</ejb-name>
        <jndi-name>SB_BrowseRegionsHome</jndi-name>
        <jonas-resource>
            <res-ref-name>jdbc/rubis</res-ref-name>
            <jndi-name>mysql</jndi-name>
        </jonas-resource>
    </jonas-session>
</jonas-ejb-jar>
         

Entity Bean

This is the jboss.xml file for Region:

<jboss>
    <entity>
      <ejb-name>Region</ejb-name>
      <jndi-name>RegionHome</jndi-name>
      <resource-ref>
        <res-ref-name>jdbc/rubis</res-ref-name>
        <resource-name>rubis</resource-name>
      </resource-ref>
    </entity>
</jboss>
         

Here is the equivalent jonas-ejb-jar.xml file:

<jonas-ejb-jar>
    <jonas-entity>
        <ejb-name>Region</ejb-name>
        <jndi-name>RegionHome</jndi-name>
        <jonas-resource>
            <res-ref-name>jdbc/rubis</res-ref-name>
            <jndi-name>rubis</jndi-name>
        </jonas-resource>
    </jonas-entity>
</jonas-ejb-jar>
         

Migrating jaws.xml

The jaws.xml file contains the mapping of the beans to the database tables and the finders declaration. You will have to move this to the jonas-ejb-jar.xml file.

This is the jaws.xml file for Region:

<jaws>
   <entity>
      <ejb-name>Region</ejb-name>
      <table-name>regions</table-name>
      <create-table>false</create-table>
      <cmp-field>
         <field-name>id</field-name>
         <column-name>id</column-name>
      </cmp-field>
      <cmp-field>
         <field-name>name</field-name>
         <column-name>name</column-name>
      </cmp-field>
   </entity>
</jaws>
         

Here is the equivalent jonas-ejb-jar.xml file:

<jonas-ejb-jar>
    <jonas-entity>
        <jdbc-mapping>
            <jndi-name>mysql</jndi-name>
            <jdbc-table-name>regions</jdbc-table-name>
            <cmp-field-jdbc-mapping>
                <field-name>id</field-name>
                <jdbc-field-name>id</jdbc-field-name>
            </cmp-field-jdbc-mapping>
            <cmp-field-jdbc-mapping>
                <field-name>name</field-name>
                <jdbc-field-name>name</jdbc-field-name>
            </cmp-field-jdbc-mapping>
        </jdbc-mapping>
    </jonas-entity>
</jonas-ejb-jar>
         

Migrating jbosscmp-jdbc.xml

The jbosscmp-jdbc.xml file contains the mapping of the beans CMP2.0 to the database tables. You will have to move this to the jonas-ejb-jar.xml file.

Relationship is one of the great innovation of CMP2.0. As an example, we use two entity beans called CustomerEJB and AddressEJB, between them we create a 1-1 relationship.

This is the jbosscmp-jdbc.xml file for CustomerEJB and AddressEJB:

<jbosscmp-jdbc>
 <entreprise-beans>
   <entity>
      <ejb-name>CustomerEJB</ejb-name>
      <table-name>customer</table-name>
      <create-table>true</create-table>
      <remove-table>true</remove-table>
      <cmp-field>
         <field-name>id</field-name>
         <column-name>id</column-name>
      </cmp-field>
      <cmp-field>
         <field-name>name</field-name>
         <column-name>name</column-name>
      </cmp-field>
   </entity>
   <entity>
      <ejb-name>AddressEJB</ejb-name>
      <table-name>address</table-name>
      <cmp-field>
         <field-name>id</field-name>
         <column-name>id</column-name>
      </cmp-field>
      <cmp-field>
         <field-name>address</field-name>
         <column-name>address</column-name>
      </cmp-field>
   </entity>
   <relationships>
      <ejb-relation>
        <ejb-relation-name>customer-address</ejb-relation-name>
        <foreign-key-mapping/>
        <ejb-relationship-role>
          <ejb-relationship-role-name>customer has address</ejb-relationship-role-name>
          <key-fields>
            <keyfield>
	      <field-name>id</field-name>
	      <column-name>fk_adr</column-name>
	    </keyfield>
	  </key-fields>
        </ejb-relationship-role>
      </ejb-relation>
   </relationships>
 </entreprise-beans>
</jbosscmp-jdbc>
         

Here is the equivalent jonas-ejb-jar.xml file:

<jonas-ejb-jar>
 <jonas-entity>
     <ejb-name>CustomerEJB</ejb-name>
     <jndi-name>CustomerHomeRemote</jndi-name>
     <cleanup>removedata</cleanup>
     <jdbc-mapping>
        <jndi-name>jdbc_1</jndi-name>
	<jdbc-table-name>customer</jdbc-table-name>
            <cmp-field-jdbc-mapping>
                <field-name>id</field-name>
                <jdbc-field-name>id</jdbc-field-name>
            </cmp-field-jdbc-mapping>
            <cmp-field-jdbc-mapping>
                <field-name>name</field-name>
                <jdbc-field-name>name</jdbc-field-name>
            </cmp-field-jdbc-mapping>
        </jdbc-mapping>
     </jdbc-mapping>
 </jonas-entity>
 <jonas-entity>
    <ejb-name>AddressEJB</ejb-name>
    <jdbc-mapping>
        <jndi-name>jdbc_1</jndi-name>
	<jdbc-table-name>address</jdbc-table-name>
	    <cmp-field-jdbc-mapping>
                <field-name>id</field-name>
                <jdbc-field-name>id</jdbc-field-name>
            </cmp-field-jdbc-mapping>
            <cmp-field-jdbc-mapping>
                <field-name>address</field-name>
                <jdbc-field-name>address</jdbc-field-name>
            </cmp-field-jdbc-mapping>
        </jdbc-mapping>
    </jdbc-mapping>
 <jonas-entity>
 <jonas-ejb-relation>
   <ejb-relation-name>customer-address</ejb-relation-name>
      <jonas-ejb-relationship-role>
        <ejb-relationship-role-name>customer has address</ejb-relationship-role-name>
        <foreign-key-jdbc-mapping>
          <foreign-key-jdbc-name>fk_adr</foreign-key-jdbc-name>
        </foreign-key-jdbc-mapping>
   </jonas-ejb-relationship-role>
 </jonas-ejb-relation>
</jonas-ejb-jar>
         

Note that the two tags "create-table" and "remove-table" in jbosscmp-jdbc.xml are optional, only the values true or false are permitted, they are used to allow JBoss to create (drop) a table at bean loading time (bean unloading time), These options are very useful during the early stages of development when the table structure changes often. In JOnAS CMP 2.0, these functions are replaced by the tag "cleanup" which may have one of the following value:

removedata: at bean loading time, the content of the tables storing the bean data is deleted

removeall: at bean loading time, the tables storing the bean data are dropped (if they exist) and created

none: do nothing

create: default value (if the element is not specified), at bean loading time, the tables for storing the bean data are created if they do not exist.

So if you want the database data to be deleted each time you load your bean, which may be useful for testing purpose, the part of the JOnAS specific deployment descriptor related to your entity bean may look like:

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