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


Use @ConversionValue to specify the database and object values for an ObjectTypeConverter.

Annotation Elements

Table 2-13 describes this annotation's elements.

Table 2-13 @ConversionValue Annotation Elements

Annotation Element Description Default


(Required) The database value.


(Required) The object value


The JPA specification allows you to map an Enum to database columns using the @Enumerated annotation, when the database value is either the name of the Enum or its ordinal value. With EclipseLink, you can also map an Enum to a coded value, using a converter.


In Example 2-29, the enum Gender(MALE, FEMALE) is mapped to a single character in the database where M=MALE and F=FEMALE.

Example 2-29 Using @ConversionValue Annotation

@ObjectTypeConverter(name = "gender", objectType = Gender.class, dataType = String.class, conversionValues = {
  @ConversionValue(objectValue = "Male", dataValue = "M"),
  @ConversionValue(objectValue = "Female", dataValue = "F") })


private Gender gender = Gender.Male;

Example 2-30 illustrates the same function using XML.

Example 2-30 Using <conversion-value> XML

<object-type-converter name="gender" object-type="model.Gender   "data-type="java.lang.String">
  <conversion-value object-value="Male" data-value="M" />
  <conversion-value object-value="Female" data-value="F" />


<basic name="gender">
  <column name="GENDER" />

See Also

For more information, see: