Use @TypeConverter to modify data values during the reading and writing of a mapped attribute.
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 |
|
Footnote 1 The default is inferred from the type of the persistence field or property.
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.
Oracle TopLink also includes @ObjectTypeConverter and @StructConverter converters.
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;
}
...
}
For more information, see: