Creating a new EJB converter

A converter is used to translate a single database column to and from the bean class field.

A set of existing converters is available in the VapAbstractConverter class hierarchy. You can also write your own converters. When you create your own converter, you subclass VapAbstractConverter or another converter. Use the New Converter wizard to add new converters to your Converters type list. After you have made the changes and saved the document, you can use the Mapping editor to work with the converter.

Restriction: The required best practice to follow when creating custom converters is to use data types that can be converted round trip. For example, if you pass object A as a parameter to dataFrom(...) to convert it into object B, object B must be able to be passed as a parameter in objectFrom(...) to convert back to object A. If you are experiencing problems with converters that you wrote and used in older versions of the workbench, make sure that they meet this requirement.

After you write the converter, you can use it in the Mapping editor. To add a new converter to the outline view, complete the following steps:

  1. In the J2EE perspective, click File > New > Other > EJB > Converter or Composer, then click Next.

  2. Select the Converter radio button.

  3. Type or select an EJB project.

  4. Type a fully qualified converter name.

  5. Type or select a fully qualified supertype.

  6. Type or select a fully qualified target type.

  7. Optionally, you can select the Generate a converter stub class check box. If you generate a converter stub class, you still need to define the implementation in the class itself.

  8. Click Finish. The converter name that you defined now appears in the Outline view when you open the Mapping editor.

    Note: This is only true for the EJB project that contains the UserDefinedConverter.xmi file. If you want to use this converter in other projects, you can copy the file to another EJB project.