| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <title>Convert</title> |
| <link rel="stylesheet" type="text/css" href="../../stylesheet.css" title="Style"> |
| <script type="text/javascript" src="../../script.js"></script> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| try { |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="Convert"; |
| } |
| } |
| catch(err) { |
| } |
| //--> |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a name="navbar.top"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> |
| <a name="navbar.top.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../overview-summary.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../index-all.html">Index</a></li> |
| <li><a href="../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../javax/persistence/ConstructorResult.html" title="annotation in javax.persistence"><span class="typeNameLink">Prev Class</span></a></li> |
| <li><a href="../../javax/persistence/Converter.html" title="annotation in javax.persistence"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../index.html?javax/persistence/Convert.html" target="_top">Frames</a></li> |
| <li><a href="Convert.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_top"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Field | </li> |
| <li>Required | </li> |
| <li><a href="#annotation.type.optional.element.summary">Optional</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#annotation.type.element.detail">Element</a></li> |
| </ul> |
| </div> |
| <a name="skip.navbar.top"> |
| <!-- --> |
| </a></div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <div class="header"> |
| <div class="subTitle">javax.persistence</div> |
| <h2 title="Annotation Type Convert" class="title">Annotation Type Convert</h2> |
| </div> |
| <div class="contentContainer"> |
| <div class="description"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <hr> |
| <br> |
| <pre>@Repeatable(value=<a href="../../javax/persistence/Converts.html" title="annotation in javax.persistence">Converts.class</a>) |
| @Target(value={METHOD,FIELD,TYPE}) |
| @Retention(value=RUNTIME) |
| public @interface <span class="memberNameLabel">Convert</span></pre> |
| <div class="block">Specifies the conversion of a Basic field or property. It is |
| not necessary to use the <code>Basic</code> annotation or corresponding |
| XML element to specify the Basic type. |
| |
| <p>The <code>Convert</code> annotation should not be used to specify |
| conversion of the following: Id attributes, version attributes, |
| relationship attributes, and attributes explicitly denoted as |
| Enumerated or Temporal. Applications that specify such conversions |
| will not be portable. |
| |
| <p>The <code>Convert</code> annotation may be applied to a basic |
| attribute or to an element collection of basic type (in which case |
| the converter is applied to the elements of the collection). In |
| these cases, the <code>attributeName</code> element must not be |
| specified. |
| |
| <p>The <code>Convert</code> annotation may be applied to an embedded |
| attribute or to a map collection attribute whose key or value is of |
| embeddable type (in which case the converter is applied to the |
| specified attribute of the embeddable instances contained in the |
| collection). In these cases, the <code>attributeName</code> |
| element must be specified. |
| |
| <p>To override conversion mappings at multiple levels of embedding, |
| a dot (".") notation form must be used in the <code>attributeName</code> |
| element to indicate an attribute within an embedded attribute. The |
| value of each identifier used with the dot notation is the name of the |
| respective embedded field or property. |
| |
| <p>When the <code>Convert</code> annotation is applied to a map containing |
| instances of embeddable classes, the <code>attributeName</code> element |
| must be specified, and <code>"key."</code> or <code>"value."</code> |
| must be used to prefix the name of the attribute that is to be converted |
| in order to specify it as part of the map key or map value. |
| |
| <p>When the <code>Convert</code> annotation is applied to a map to specify |
| conversion of a map key of basic type, <code>"key"</code> must be used |
| as the value of the <code>attributeName</code> element to specify that |
| it is the map key that is to be converted. |
| |
| <p>The <code>Convert</code> annotation may be applied to an entity class |
| that extends a mapped superclass to specify or override a conversion |
| mapping for an inherited basic or embedded attribute. |
| |
| <pre> |
| Example 1: Convert a basic attribute |
| |
| @Converter |
| public class BooleanToIntegerConverter |
| implements AttributeConverter<Boolean, Integer> { ... } |
| |
| @Entity |
| public class Employee { |
| @Id long id; |
| |
| @Convert(converter=BooleanToIntegerConverter.class) |
| boolean fullTime; |
| ... |
| } |
| |
| |
| Example 2: Auto-apply conversion of a basic attribute |
| |
| @Converter(autoApply=true) |
| public class EmployeeDateConverter |
| implements AttributeConverter<com.acme.EmployeeDate, java.sql.Date> { ... } |
| |
| @Entity |
| public class Employee { |
| @Id long id; |
| ... |
| // EmployeeDateConverter is applied automatically |
| EmployeeDate startDate; |
| } |
| |
| |
| Example 3: Disable conversion in the presence of an autoapply converter |
| |
| @Convert(disableConversion=true) |
| EmployeeDate lastReview; |
| |
| |
| Example 4: Apply a converter to an element collection of basic type |
| |
| @ElementCollection |
| // applies to each element in the collection |
| @Convert(converter=NameConverter.class) |
| List<String> names; |
| |
| |
| Example 5: Apply a converter to an element collection that is a map or basic values. |
| The converter is applied to the map value. |
| |
| @ElementCollection |
| @Convert(converter=EmployeeNameConverter.class) |
| Map<String, String> responsibilities; |
| |
| |
| Example 6: Apply a converter to a map key of basic type |
| |
| @OneToMany |
| @Convert(converter=ResponsibilityCodeConverter.class, |
| attributeName="key") |
| Map<String, Employee> responsibilities; |
| |
| |
| Example 7: Apply a converter to an embeddable attribute |
| |
| @Embedded |
| @Convert(converter=CountryConverter.class, |
| attributeName="country") |
| Address address; |
| |
| |
| Example 8: Apply a converter to a nested embeddable attribute |
| |
| @Embedded |
| @Convert(converter=CityConverter.class, |
| attributeName="region.city") |
| Address address; |
| |
| |
| Example 9: Apply a converter to a nested attribute of an embeddable that is a map key |
| of an element collection |
| |
| @Entity public class PropertyRecord { |
| ... |
| @Convert(attributeName="key.region.city", |
| converter=CityConverter.class) |
| @ElementCollection |
| Map<Address, PropertyInfo> parcels; |
| } |
| |
| |
| Example 10: Apply a converter to an embeddable that is a map key for a relationship |
| |
| @OneToMany |
| @Convert(attributeName="key.jobType", |
| converter=ResponsibilityTypeConverter.class) |
| Map<Responsibility, Employee> responsibilities; |
| |
| |
| Example 11: Override conversion mappings for attributes inherited from a mapped superclass |
| |
| @Entity |
| @Converts({ |
| @Convert(attributeName="startDate", |
| converter=DateConverter.class), |
| @Convert(attributeName="endDate", |
| converter=DateConverter.class)}) |
| public class FullTimeEmployee extends GenericEmployee { ... } |
| </pre></div> |
| <dl> |
| <dt><span class="simpleTagLabel">Since:</span></dt> |
| <dd>Java Persistence 2.1</dd> |
| <dt><span class="seeLabel">See Also:</span></dt> |
| <dd><a href="../../javax/persistence/Converter.html" title="annotation in javax.persistence"><code>Converter</code></a>, |
| <a href="../../javax/persistence/Converts.html" title="annotation in javax.persistence"><code>Converts</code></a>, |
| <a href="../../javax/persistence/Basic.html" title="annotation in javax.persistence"><code>Basic</code></a></dd> |
| </dl> |
| </li> |
| </ul> |
| </div> |
| <div class="summary"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- =========== ANNOTATION TYPE OPTIONAL MEMBER SUMMARY =========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="annotation.type.optional.element.summary"> |
| <!-- --> |
| </a> |
| <h3>Optional Element Summary</h3> |
| <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Optional Element Summary table, listing optional elements, and an explanation"> |
| <caption><span>Optional Elements</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Modifier and Type</th> |
| <th class="colLast" scope="col">Optional Element and Description</th> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>java.lang.String</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../javax/persistence/Convert.html#attributeName--">attributeName</a></span></code> |
| <div class="block">The <code>attributeName</code> element must be specified unless the |
| <code>Convert</code> annotation is on an attribute of basic type |
| or on an element collection of basic type.</div> |
| </td> |
| </tr> |
| <tr class="rowColor"> |
| <td class="colFirst"><code>java.lang.Class</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../javax/persistence/Convert.html#converter--">converter</a></span></code> |
| <div class="block">Specifies the converter to be applied.</div> |
| </td> |
| </tr> |
| <tr class="altColor"> |
| <td class="colFirst"><code>boolean</code></td> |
| <td class="colLast"><code><span class="memberNameLink"><a href="../../javax/persistence/Convert.html#disableConversion--">disableConversion</a></span></code> |
| <div class="block">Used to disable an auto-apply or inherited converter.</div> |
| </td> |
| </tr> |
| </table> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| <div class="details"> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== --> |
| <ul class="blockList"> |
| <li class="blockList"><a name="annotation.type.element.detail"> |
| <!-- --> |
| </a> |
| <h3>Element Detail</h3> |
| <a name="converter--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>converter</h4> |
| <pre>public abstract java.lang.Class converter</pre> |
| <div class="block">Specifies the converter to be applied. A value for this |
| element must be specified if multiple converters would |
| otherwise apply.</div> |
| <dl> |
| <dt>Default:</dt> |
| <dd>void.class</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <ul class="blockList"> |
| <li class="blockList"><a name="attributeName--"> |
| <!-- --> |
| </a> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <h4>attributeName</h4> |
| <pre>public abstract java.lang.String attributeName</pre> |
| <div class="block">The <code>attributeName</code> element must be specified unless the |
| <code>Convert</code> annotation is on an attribute of basic type |
| or on an element collection of basic type. In these cases, the |
| <code>attributeName</code> element must not be specified.</div> |
| <dl> |
| <dt>Default:</dt> |
| <dd>""</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <ul class="blockList"> |
| <li class="blockList"><a name="disableConversion--"> |
| <!-- --> |
| </a> |
| <ul class="blockListLast"> |
| <li class="blockList"> |
| <h4>disableConversion</h4> |
| <pre>public abstract boolean disableConversion</pre> |
| <div class="block">Used to disable an auto-apply or inherited converter. |
| If disableConversion is true, the <code>converter</code> element should |
| not be specified.</div> |
| <dl> |
| <dt>Default:</dt> |
| <dd>false</dd> |
| </dl> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| </div> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a name="navbar.bottom"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> |
| <a name="navbar.bottom.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../overview-summary.html">Overview</a></li> |
| <li><a href="package-summary.html">Package</a></li> |
| <li class="navBarCell1Rev">Class</li> |
| <li><a href="package-tree.html">Tree</a></li> |
| <li><a href="../../deprecated-list.html">Deprecated</a></li> |
| <li><a href="../../index-all.html">Index</a></li> |
| <li><a href="../../help-doc.html">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList"> |
| <li><a href="../../javax/persistence/ConstructorResult.html" title="annotation in javax.persistence"><span class="typeNameLink">Prev Class</span></a></li> |
| <li><a href="../../javax/persistence/Converter.html" title="annotation in javax.persistence"><span class="typeNameLink">Next Class</span></a></li> |
| </ul> |
| <ul class="navList"> |
| <li><a href="../../index.html?javax/persistence/Convert.html" target="_top">Frames</a></li> |
| <li><a href="Convert.html" target="_top">No Frames</a></li> |
| </ul> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="../../allclasses-noframe.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_bottom"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| </div> |
| <div> |
| <ul class="subNavList"> |
| <li>Summary: </li> |
| <li>Field | </li> |
| <li>Required | </li> |
| <li><a href="#annotation.type.optional.element.summary">Optional</a></li> |
| </ul> |
| <ul class="subNavList"> |
| <li>Detail: </li> |
| <li>Field | </li> |
| <li><a href="#annotation.type.element.detail">Element</a></li> |
| </ul> |
| </div> |
| <a name="skip.navbar.bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </body> |
| </html> |