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.
Difference between revisions of "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
m |
m |
||
Line 62: | Line 62: | ||
|next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Basic_Mappings/Default_Conversions_and_Converters/TypeConverter|@TypeConverter]] | |next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Basic_Mappings/Default_Conversions_and_Converters/TypeConverter|@TypeConverter]] | ||
|up=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Basic_Mappings/Default_Conversions_and_Converters|Default Conversions and Converters]] | |up=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Basic_Mappings/Default_Conversions_and_Converters|Default Conversions and Converters]] | ||
− | |version=2. | + | |version=2.2.0 DRAFT |
}} | }} |
Revision as of 13:51, 15 February 2011
EclipseLink JPA
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
Key API
@Converter Annotation
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(); }
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 | |
converterClass | Set this attribute to the Class of your converter. This class must implement the EclipseLink org.eclipse.persistence.mappings.converters.Converter interface. | Yes |
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; } ... }