Jump to: navigation, search

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

m (@Convert Annotation)
m (@Convert Annotation)
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]
 
}}
 
}}
=@Convert Annotation=
+
=@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.
 
<source lang="java">
 
<source lang="java">
Line 65: Line 65:
  
 
{{EclipseLink_JPA
 
{{EclipseLink_JPA
|previous=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Basic_Mappings/Default_Conversions_and_Converters/StructConverter|@StructConverter]]
+
|previous=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Basic_Mappings/Default_Conversions_and_Converters/StructConverter|Struct Converter]]
 
|next=    [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Basic_Mappings/Lazy_Basics|Lazy Basics]]
 
|next=    [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Basic_Mappings/Lazy_Basics|Lazy Basics]]
 
|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.1.0
 
|version= 2.1.0
 
}}
 
}}

Revision as of 14:15, 17 June 2010


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

@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.

This table lists attributes of the @Convert annotation.

Attributes of the @Convert Annotation

Attribute Description Default Required or Optional

value

Set this attribute to the String name for your converter.

"none" String

optional


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.1.0
Other versions...