Notice: this Wiki will be going read only early in 2024 and edits will no longer be 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/Convert"
< EclipseLink | UserGuide | JPA | Basic JPA Development | Mapping | Basic Mappings | Default Conversions and Converters
m |
m |
||
Line 17: | Line 17: | ||
* <tt>none</tt> – does not place a converter on the associated mapping. | * <tt>none</tt> – does not place a converter on the associated mapping. | ||
− | + | {{EclipseLink_AttributesTable | |
− | + | |caption=Attributes of the <tt>@Convert</tt> annotation | |
− | < | + | |content=<tr> |
− | ''' | + | <td>'''<tt>value</tt>'''</td> |
− | + | <td>The <tt>String</tt> name for your converter.</td> | |
− | + | <td><tt>"none" String</tt></td> | |
− | + | <td>No</td> | |
− | + | </tr> | |
− | + | }} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | <tt>value</tt> | + | |
− | + | ||
− | + | ||
− | + | ||
− | <tt>"none" String</tt> | + | |
− | + | ||
− | + | ||
− | + | ||
Revision as of 13:52, 18 June 2010
@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.
Template:EclipseLink AttributesTable
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; } ... }