Creating a new EJB composer
A composer class is used to map a single complex bean field to multiple database columns. This composition is needed for complex fields that are themselves objects with fields and behavior.
Consider the following example: In your CustomerBean CMP entity bean, you have an attribute called CustomerAddress. The type of the CustomerAddress attribute is a complex type that you defined in a class called Address.class, which contains multiple Java fields: street, city, and zip. In order to map the complex CustomerAddress type to different columns in a table, you need a new composer class that defines which fields in the composed type class (Address.class) map to which columns in the database. The composer class composes the Address.class making it possible for you to map the CustomerAddress attribute in CustomerBean.
Use the New Composer wizard to add a new composer definition to your type list. After you create the new composer definition, you can use the composer class in the Mapping editor.
Restrictions and notes:
- The Java field names in the composed class must match exactly the attribute names in the getAttributes method of the composer class. If these field names do not match, the Tasks view displays a warning.
- If you choose to generate a stub composer class with the wizard, the generated composer class is incomplete. You need to define the dataFrom and objectFrom methods in the composer class. The wizard is unable to guess which fields are mapped to what part of the composed type, so implement these methods before using the composer in a mapping.
- After you create a composer, you can use it in other projects by copying the userDefinedComposer.xmi file, the composer class, and the composed type class to another EJB project.
- Nested composers are not supported by the composer wizard. In other words, the wizard does not support composing fields that are already composed types.
- Composer maps do not support converters. If converters are required between two types, this must be handled in the dataFrom and ObjectFrom methods of the composer by creating an instance of the converter.
To create a new composer definition:
- In the J2EE perspective, select File > New > Other > EJB > Converter or Composer, then click Next.
- Select the Composer radio button.
- Type or select an EJB project.
- Type a fully qualified composer name.
- Type or select a fully qualified supertype.
- Type or select a fully qualified target type.
- Add or select the New composed field type. You must select more than one composed field type.
- Additionally, you can Remove a selected field.
- Optional: Select the Generate a composer stub class check box to generate a new composer class template for the new composer definition. The composer stub class that is generated is not complete. It is up to you to define the dataFrom and objectFrom methods.
- Click Finish. When you open the Mapping editor, the composer name that you defined appears in the Outline view.