blob: 26423b0161c675a04180998e5bade5371fc3b75e [file] [log] [blame]
<!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&nbsp;Class</span></a></li>
<li><a href="../../javax/persistence/Converter.html" title="annotation in javax.persistence"><span class="typeNameLink">Next&nbsp;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&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../allclasses-noframe.html">All&nbsp;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:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</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
&#064;Converter
public class BooleanToIntegerConverter
implements AttributeConverter&#060;Boolean, Integer&#062; { ... }
&#064;Entity
public class Employee {
&#064;Id long id;
&#064;Convert(converter=BooleanToIntegerConverter.class)
boolean fullTime;
...
}
Example 2: Auto-apply conversion of a basic attribute
&#064;Converter(autoApply=true)
public class EmployeeDateConverter
implements AttributeConverter&#060;com.acme.EmployeeDate, java.sql.Date&#062; { ... }
&#064;Entity
public class Employee {
&#064;Id long id;
...
// EmployeeDateConverter is applied automatically
EmployeeDate startDate;
}
Example 3: Disable conversion in the presence of an autoapply converter
&#064;Convert(disableConversion=true)
EmployeeDate lastReview;
Example 4: Apply a converter to an element collection of basic type
&#064;ElementCollection
// applies to each element in the collection
&#064;Convert(converter=NameConverter.class)
List&#060;String&#062; 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.
&#064;ElementCollection
&#064;Convert(converter=EmployeeNameConverter.class)
Map&#060;String, String&#062; responsibilities;
Example 6: Apply a converter to a map key of basic type
&#064;OneToMany
&#064;Convert(converter=ResponsibilityCodeConverter.class,
attributeName="key")
Map&#060;String, Employee&#062; responsibilities;
Example 7: Apply a converter to an embeddable attribute
&#064;Embedded
&#064;Convert(converter=CountryConverter.class,
attributeName="country")
Address address;
Example 8: Apply a converter to a nested embeddable attribute
&#064;Embedded
&#064;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
&#064;Entity public class PropertyRecord {
...
&#064;Convert(attributeName="key.region.city",
converter=CityConverter.class)
&#064;ElementCollection
Map&#060;Address, PropertyInfo&#062; parcels;
}
Example 10: Apply a converter to an embeddable that is a map key for a relationship
&#064;OneToMany
&#064;Convert(attributeName="key.jobType",
converter=ResponsibilityTypeConverter.class)
Map&#060;Responsibility, Employee&#062; responsibilities;
Example 11: Override conversion mappings for attributes inherited from a mapped superclass
&#064;Entity
&#064;Converts({
&#064;Convert(attributeName="startDate",
converter=DateConverter.class),
&#064;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">&nbsp;</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&nbsp;java.lang.Class&nbsp;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&nbsp;java.lang.String&nbsp;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&nbsp;boolean&nbsp;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&nbsp;Class</span></a></li>
<li><a href="../../javax/persistence/Converter.html" title="annotation in javax.persistence"><span class="typeNameLink">Next&nbsp;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&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../allclasses-noframe.html">All&nbsp;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:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</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>