Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

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

< EclipseLink‎ | UserGuide‎ | JPA‎ | Basic JPA Development‎ | Mapping‎ | Basic Mappings‎ | Default Conversions and Converters
Revision as of 09:29, 17 June 2010 by Unnamed Poltroon (Talk) (New page: =@Converter= You can use <tt>@Converter</tt> annotation to specify a custom converter for modification of the data value(s) during the reading and writing of a mapped attribute. <source la...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

@Converter

You can use @Converter annotation to specify a custom converter for modification of the data value(s) during the reading and writing of a mapped attribute.

 
 @Target({TYPE, METHOD, FIELD})
 @Retention(RUNTIME)
 public @interface Converter {
    String name();
    Class converterClass(); 
 }

This table lists attributes of the @Converter annotation.

Attribute Description Default Required or Optional

name

Set this attribute to the String name for your converter. Ensure that this name is unique across the persistence unit

no default

required

converterClass

Set this attribute to the Class of your converter. This class must implement the EclipseLink org.eclipse.persistence.mappings.converters.Converter interface.

no default

required


This example shows how to use the @Converter annotation to specify Employee field gender.

Usage of the @Converter Annotation

 @Entity
 public class Employee implements Serializable{
     ...
     @Basic
     @Converter (
         name="genderConverter",
         converterClass=org.myorg.converters.GenderConverter.class
     )
     @Convert("genderConverter")
     public String getGender() {
         return gender;
     }
     ...
}



Eclipselink-logo.gif
Version: 2.1.0
Other versions...

Back to the top