8.10. JOnAS Database Mappers

For implementing the EJB 2.0 persistence (CMP2.0), JOnAS relies on the JORM framework (see http://www.objectweb.org/jorm/index.html). JORM itself relies on JOnAS DataSources (specified in DataSource properties files) for connecting to the actual database. JORM must adapt its object-relational mapping to the underlying database, for which it makes use of adapters called mappers. Thus, for each type of database (and more precisely for each JDBC driver), the corresponding mapper must be specified in the DataSource. This is the purpose of the datasource.mapper property of the DataSource properties file. Note that all JOnAS-provided DataSource properties files (in $JONAS_ROOT/conf) already contain this property with the correct mapper.

For the JORM database mapper datasource.mapper, the possible values are:

Contact the JOnAS team ([email protected]) to obtain a mapper for other databases.

The container code generated at deployment (GenIC or EJB-JAR Ant task) is dependent on this mapper. It is possible to deploy (generate container code) a bean for several mappers in order to change the database (that is, the DataSource file) without redeploying the bean. These mappers should be specified as the mappernames argument of the GenIC command or as the mappernames attribute of the JOnAS ANT EJB-JAR task. The value is a comma-separated list of mapper names for which the container classes will be generated. This list of mapper names corresponds to the list of potential databases upon which you can deploy your Entity Beans. For example, to deploy Entity Beans so that they can be used on either Oracle or PostgreSQL, run GenIC as:

GenIC -mappernames rdb.oracle,rdb.postgres eb.jar

The following is the same example in an Ant build.xml file:

<target name="deploy"
        description="Build and deploy the ejb-jars"
        depends="compile>
  <ejbjar naming="directory"
      ....
      ....
    <jonas destdir="${ejbjars.dir}"
           jonasroot="${jonas.root}"
           orb="${orb}"
           jarsuffix=".jar"
           secpropag="yes"
           keepgenerated="true"
           mappernames="${mapper.names}"
           additionalargs="${genicargs}">
    </jonas>
    ...
    ... 
  </ejbjar>
</target>

that have the following in build.properties:

# mappers for entity CMP2
mapper.names            rdb.oracle,rdb.postgres