Use @TypeConverter
to modify data values during the reading and writing of a mapped attribute.
Annotation Elements
Table 2-72 describes this annotation's elements.
Table 2-72 @TypeConverter Annotation Elements
Annotation Element | Description | Default |
---|---|---|
|
(Required) The |
none |
|
(Optional) The |
|
|
(Optional) The |
|
Usage
Each TypeConverter
must be uniquely named and can be defined at the class, field and property level and can be specified within an Entity, MappedSuperclass and Embeddable class. A TypeConverter
is always specified by using an @Convert
annotation
You can place a @TypeConverter
on a Basic
, BasicMap
or BasicCollection
mapping.
EclipseLink also includes @ObjectTypeConverter
and @StructConverter
converters.
Examples
Example 2-116 shows how to use the @TypeConverter
annotation to convert the Double
value stored in the database to a Float
value stored in the entity.
Example 2-116 Using the @TypeConverter Annotation
@Entity public class Employee implements Serializable{ ... @TypeConverter ( name="doubleToFloat", dataType=Double.class, objectType=Float.class, ) @Convert("doubleToFloat") public Number getGradePointAverage() { return gradePointAverage; } ... }
See Also
For more information, see: