Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.4
  Go To Table Of Contents
 Search
 PDFComments
Comments


@Transformation

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

fetch

(Optional) Defines whether the value of the field or property should be lazily loaded or must be eagerly fetched.

  • The EAGER strategy is a requirement on the persistence provider runtime that the value must be eagerly fetched.

  • The LAZY strategy is a hint to the persistence provider runtime.

EAGER

optional

(Optional) A hint as to whether the value of the field or property may be null. It is disregarded for primitive types, which are considered non-optional.

true



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: