Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: for the plan.

Jump to: navigation, search

EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Default Conversions and Converters/TypeConverter

Elug api package icon.png Key API {{{apis}}}

@TypeConverter Annotation

The @TypeConverter is an EclipseLink-specific annotation. You can use it to specify an org.eclipse.persistence.mappings.converters.TypeConversionConverter for modification of the data value(s) during the reading and writing of a mapped attribute.

 public @interface TypeConverter {
    String name();
    Class dataType() default void.class;
    Class objectType() default void.class;
Attribute Description Default Required?
name Set this attribute to the String name for your converter. Ensure that this name is unique across the persistence unit. Yes
dataType Set this attribute to the type stored in the database. void.class1 No
objectType Set the value of this attribute to the type stored on the entity. void.class1 No

1 The default is inferred from the type of the persistence field or property.

This example shows how to use the @TypeConverter annotation to convert the Double value stored in the database to a Float value stored in the entity.

Usage of the @TypeConverter Annotation

 public class Employee implements Serializable{
     @TypeConverter (
     public Number getGradePointAverage() {
         return gradePointAverage;

Version: 2.1.0
Other versions...

Back to the top