With user-type-mapping elements in jbosscmp-jdbc.xml
it is possible to map any class to one column in a
database table. An example:
<user-type-mappings>
<user-type-mapping>
<java-
type>org.jboss.test.cmp2.enum.ejb.ColorEnum</java-
type>
<mapped-type>java.lang.Integer</mapped-type>
<mapper>org.jboss.test.cmp2.enum.ejb.ColorMapper</ma
pper>
</user-type-mapping>
</user-type-mappings>
ColorMapper serves as a mediator when data is stored
and loaded.
When data is stored, ColorMapper translates CMP field
value of type ColorEnum to an Integer instance which is
stored in the column of the table.
When data is loaded, ColorMapper translates loaded
Integer value into ColorEnum which is used then as a
CMP field value.
Logged In: YES
user_id=543482
ColorMapper is provided by application developer and must
implement org.jboss.ejb.plugins.cmp.jdbc.Mapper interface
public interface Mapper
{
/**
* This method is called when CMP field is stored.
* @param fieldValue - CMP field value
* @return column value.
*/
Object toColumnValue(Object fieldValue);
/**
* This method is called when CMP field is loaded.
* @param columnValue - loaded column value.
* @return CMP field value.
*/
Object toFieldValue(Object columnValue);
}