Converters and composers

Converters and composers are used by enterprise beans to handle and map relational data.

In the J2EE perspective, you can use the Converter or Composer wizard to create a converter or composer. Converters and composers can be set from the Properties view of the Mapping editor after selecting the attribute map in the Outline view or Overview pane of the editor.

 

Converters

At times, you might need to convert data that is read from a database or saved to a database. Converters translate a database representation to an object type, and they convert object types back to database representations. For example, you might want to convert a CHAR database entry 'Y' to a Boolean object set to true. In this case, you can specify the VapStringToBooleanConverter in the Properties view of the Mapping editor for the selected attribute map.

For many column types, no converter is required, because the object type can be derived from the database representation. VapTrimStringConverter is handy for strings because it strips off leading and trailing blanks from the data being read.

In most cases, the name of the converter specifies the database and object types. The first type specified is the database type.

 

Composers

A composer is used to map a single complex bean field to multiple database columns. The complex field is a composed type. Composition is needed for complex fields that are themselves objects with fields and behavior. For instance, a bean field Name may be mapped to multiple columns such as firstName, middleName, LastName. This is an example requiring a Name composer.

In order to complete a composed mapping, use the EJB composer wizard to select an appropriate EJB composer. Once you have selected an EJB composer, use the table to match each mapped table column with the appropriate composed attribute of the composed type.