Use @Transformation
with a Transformation mapping to define the transformation of database columns into attribute values (unless the Transformation mapping is write-only, in which case it should have a @ReadTransformer
annotation).
Annotation Elements
Table 2-71 describes this annotation's elements.
Table 2-71 @Transformation Annotation Elements
Annotation Element | Description | Default |
---|---|---|
|
(Optional) Defines whether the value of the field or property should be lazily loaded or must be eagerly fetched.
|
|
|
(Optional) A hint as to whether the value of the field or property may be |
|
Usage
Unless it's a read-only mapping, either WriteTransformer
annotation or WriteTransformers
annotation should be specified. Each WriteTransformer
defines transformation of the attribute value to a single database column value (column is specified in the WriteTransformer
).
Examples
Example 2-114 shows how to use the @Transformation
annotation.
Example 2-114 Using @Transformation Annotation
@Transformation(fetch=FecthType.LAZY, optional="true") @ReadTransformer(class=package.MyNormalHoursTransformer.class) @WriteTranformers({ @WriteTranformer(column=@Column(name="START_TIME"), method="getStartDate"), @WriteTranformer(column=@Column(name="END_TIME"), class=package.MyTimeTransformer.class) }) @Mutable @ReturnUpdate @Access(AccessType.PROPERTY) @AccessMethods(get="getNormalHours", set="setNormalHours") @Properties({ @Property(name="x", value="y") })
Example 2-115 shows the same mapping, using the <transformation>
XML element in the eclipselink-orm.xml
file.
Example 2-115 Using <transformation> XML
<transformation name="normalHours" fetch="LAZY" optional="true"> <read-transformer method="buildNormalHours"/> <write-transformer method="getStartTime"> <column name="START_TIME"/> </write-transformer> <write-transformer class="package.MyTimeTransformer"> <column name="END_TIME"/> </write-transformer> <mutable/> <return-update/> <access type="PROPERTY"/> <access-methods get="getNormalHours" set="setNormalHours"/> <properties> <property name="x" value="y"/> </properties> </transformation>
See Also
For more information, see: