31.13.3. Mapping

A type-mapping is simply a set of mappings between Java class types and database types. A set of type mappings is defined by a set of mapping elements, the content model for which is shown in Figure 31.19, “The jbosscmp-jdbc mapping element content model.”.
The jbosscmp-jdbc mapping element content model.

Figure 31.19. The jbosscmp-jdbc mapping element content model.

If JBoss cannot find a mapping for a type, it will serialize the object and use the java.lang.Object mapping. The following describes the three child elements of the mapping element:
  • java-type: This required element gives the fully qualified name of the Java class to be mapped. If the class is a primitive wrapper class such as java.lang.Short, the mapping also applies to the primitive type.
  • jdbc-type: This required element gives the JDBC type that is used when setting parameters in a JDBC PreparedStatement or loading data from a JDBC ResultSet. The valid types are defined in java.sql.Types.
  • sql-type: This required element gives the SQL type that is used in create table statements. Valid types are only limited by your database vendor.
  • param-setter: This optional element specifies the fully qualified name of the JDBCParameterSetter implementation for this mapping.
  • result-reader: This option element specifies the fully qualified name of the JDBCResultSetReader implementation for this mapping.
An example mapping element for a short in Oracle9i is shown below.
<jbosscmp-jdbc>
    <type-mappings>
        <type-mapping>
            <name>Oracle9i</name>
            <!--...-->
            <mapping>
                <java-type>java.lang.Short</java-type>
                <jdbc-type>NUMERIC</jdbc-type>
                <sql-type>NUMBER(5)</sql-type>
            </mapping>
        </type-mapping>
    </type-mappings>
</jbosscmp-jdbc>