Use @WriteTransformer
on a TranformationMapping
to transform a single attribute value to a single database column value. Use the @WriteTransformers
annotation to wrap multiple transformations.
Annotation Elements
Table 2-80 describes this annotation's elements.
Table 2-80 @WriteTransformer Annotation Elements
Annotation Element | Description | Default |
---|---|---|
|
(Optional) The column into which the value should be written. If a single |
|
|
(Optional) The Note: To support DDL generation and returning policy, the method should be defined to return a particular type, not just an The method may require |
|
|
(Optional) User-defined class that implements the Note: To support DDL generation and returningpolicy, the method |
|
Note: You must specify either |
Usage
You cannot define a @WriteTransforme
r for a read-only mapping.
Unless the TransformationMapping
is write-only, it should include a ReadTransformer
that defines the transformation of the database column values into attribute values.
Configuring Field Transformer Associations
Using a FieldTransformer
is non-intrusive; your domain object does not need to implement an EclipseLink interface or provide a special transformation method.
You can configure a method-based field transformer using AbstractTransformationMapping
method addFieldTransformation
, passing in the name of the database field and the name of the domain object method to use.
You can configure a class-based field transformer using AbstractTransformationMapping
method addFieldTransformer
, passing in the name of the database field and an instance of org.eclipse.persistence.mappings.Transfomers.FieldTransformer
.
A convenient way to create a FieldTransformer
is to extend FieldTransformerAdapter
.
Examples
See "Using @Transformation Annotation" for an example of how to use the @WriteTransformer annotation
with a Transformation mapping.
See Also
For more information, see:
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Print_Version#How_to_Use_the_.40Transformation_Annotation