The @ObjectTypeConverter annotation specifies an org.eclipse.persistence.mappings.converters.ObjectTypeConverter that converts a fixed number of database data value(s) to Java object value(s) during the reading and writing of a mapped attribute.
Annotation Elements
Table 2-43 describes this annotation's elements.
Table 2-43 @ObjectTypeConverter Annotation Elements
| Annotation Element | Description | Default |
|---|---|---|
|
|
Set this attribute to the |
none |
|
|
(Optional) Set this attribute to the type stored in the database. |
|
|
|
(Optional) Set the value of this attribute to the type stored on the entity. |
|
|
|
Set the value of this attribute to the array of conversion values (instances of |
none |
|
|
Set the value of this attribute to the default object value. Note that this argument is for dealing with legacy data if the data value is missing. |
Empty |
Usage
EclipseLink also includes @TypeConverter and @StructConverter converters.
Examples
Example 2-80 shows how to use the @ObjectTypeConverter annotation to specify object converters for the gender field.
Example 2-80 Using the @ObjectTypeConverter Annotation
public class Employee implements Serializable{
...
@ObjectTypeConverter (
name="genderConverter",
dataType=java.lang.String.class,
objectType=java.lang.String.class,
conversionValues={
@ConversionValue(dataValue="F", objectValue="Female"),
@ConversionValue(dataValue="M", objectValue="Male")}
)
@Convert("genderConverter")
public String getGender() {
return gender;
}
...
}
You can use the <object-type-converter> element in the deployment descriptor as an alternative to using the @ObjectTypeConverter annotation in the source code, as shown in Example 2-81.
Example 2-81 Using <object-type-converter> XML
<object-type-converter name="gender-converter" 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" /> </object-type-converter>
See Also
For more information, see: