IBM Support

Overriding annotation merge behavior during UML-to-Java or related transformations

Technote (FAQ)


The default merge behavior for annotations during UML-to-Java or related transformations, such as UML-to-EJB 3.0, UML-to-JPA, etc, is to overwrite modelable annotations and retain unmodelable and user added annotations in the target. If an end user wants to customize this behavior, there should be a facility to make this customization easier.


In version 8.5.1, it is possible to override the behavior of annotation generation during UML-to-Java or related transformations, by writing a simple UML-to-Java transformation extension.

The extension entails extending the Java transformation and adding a custom rule to the root transformation. Care should be taken to insert the rule before the GenerateRule rule executes.

The following entry in the plugin.xml of the extension should suffice (the below example caters to JPA transformation) :

name="Test java extension"
description="Test java extension description"


<ExtendTransform targetTransform="">
<AddRule id="" insertAtID="" />


Following this, the desired annotation merge behavior can be achieved by customizing the custom rule body.

For instance, to ensure that a certain annotation is never deleted during a UML-to-Java transformation, the following code can be added :

protected Object createTarget(ITransformContext context) throws Exception { // get source
AnnotationMergerInfoCache mergeCache = ContextPropertyUtil.getAnnotationMergeInfoMap(context);
// With the below change, the Table annotations are never deleted from the code by the transformation
return context.getTarget();

To apply this behavior for multiple annotations, each of the annotation names can be removed from the merge cache similarly.

The above snippets can be found in the attached example which is a running UML-to-Java transformation extension. The attached plug-in project can be exported as a plug-in and installed on a product installation with version 8.5.1, or later.

The Eclipse plug-in installation instructions depends on the operation system. Refer to the Eclipse site or forums for detailed installation instructions for Eclipse plug-ins for the concerned operating system.

Cross reference information
Segment Product Component Platform Version Edition
Software Development Rational Software Architect for WebSphere Software Transformation Linux, Windows 8.5.1
Software Development Rational Software Architect RealTime Edition Transformation Linux, Solaris, Windows 8.5.1

Document information

More support for: Rational Software Architect

Software version: 8.5.1

Operating system(s): Linux, Windows

Reference #: 1619212

Modified date: 11 December 2012

Translate this page: