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/Converter"
< EclipseLink | UserGuide | JPA | Basic JPA Development | Mapping | Basic Mappings | Default Conversions and Converters
m (→@Converter) |
m (→@Converter) |
||
Line 11: | Line 11: | ||
} | } | ||
</source> | </source> | ||
− | + | {{EclipseLink_AttributeTable | |
− | + | |caption=<span id="Table 19-7">@Converter Attributes</span> | |
− | <span id="Table 19-7"></span> | + | |content=<tr> |
− | + | <td>'''<tt>name</tt>'''</td> | |
− | + | <td>Set this attribute to the <tt>String</tt> name for your converter. Ensure that this name is unique across the persistence unit</td> | |
− | + | <td></td> | |
− | + | <td>Yes</td> | |
− | + | </tr> | |
− | + | <tr> | |
− | + | <td>'''<tt>converterClass</tt>'''</td> | |
− | + | <td>Set this attribute to the <tt>Class</tt> of your converter. This class must implement the EclipseLink <tt>org.eclipse.persistence.mappings.converters.Converter</tt> interface.</td> | |
− | <tt>name</tt> | + | <td></td> |
− | + | <td>Yes</td> | |
− | Set this attribute to the <tt>String</tt> name for your converter. Ensure that this name is unique across the persistence unit | + | </tr> |
− | + | }} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | <tt>converterClass</tt> | + | |
− | + | ||
− | Set this attribute to the <tt>Class</tt> of your converter. This class must implement the EclipseLink <tt>org.eclipse.persistence.mappings.converters.Converter</tt> interface. | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
This example shows how to use the <tt>@Converter</tt> annotation to specify <tt>Employee</tt> field <tt>gender</tt>. | This example shows how to use the <tt>@Converter</tt> annotation to specify <tt>Employee</tt> field <tt>gender</tt>. |
Revision as of 14:16, 17 June 2010
@Converter
Key API {{{apis}}}
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; } ... }