Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Default Conversions and Converters/Convert"

m
m (@Convert Annotation and XML)
Line 2: Line 2:
 
|1=*[http://www.eclipse.org/eclipselink/api/ org.eclipse.persistence.mappings.converters.SerializedObjectConverter]
 
|1=*[http://www.eclipse.org/eclipselink/api/ org.eclipse.persistence.mappings.converters.SerializedObjectConverter]
 
}}
 
}}
 +
{{EclipseLink_UserGuide
 +
|info=y
 +
|toc=n
 +
|eclipselink=y
 +
|eclipselinktype=JPA}}
 
=@Convert Annotation and <convert> XML =
 
=@Convert Annotation and <convert> XML =
 
The <tt>@Convert</tt> annotation specifies that a named converter should be used with the corresponding mapped attribute.
 
The <tt>@Convert</tt> annotation specifies that a named converter should be used with the corresponding mapped attribute.

Revision as of 13:11, 12 January 2011


link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

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


EclipseLink JPA

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

@Convert Annotation and <convert> XML

The @Convert annotation specifies that a named converter should be used with the corresponding mapped attribute.

 @Target({METHOD, FIELD})
 @Retention(RUNTIME)
 public @interface Convert {
    String value() default "none";
 }

The @Convert has the following reserved names:

  • serialized – places the org.eclipse.persistence.mappings.converters.SerializedObjectConverter on the associated mapping.
  • none – does not place a converter on the associated mapping.
Attributes of the @Convert annotation
Attribute Description Default Required?
value The String name for your converter. "none" String No


This example shows how to use the @Convert annotation to define the Employee field gender.

Usage of the @Convert Annotation

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



Eclipselink-logo.gif
Version: 2.2.0 DRAFT
Other versions...