blob: 32d6ef8dba4b962e4f1372bd45584ba539f4260a [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>3.&nbsp; Column</title><link rel="stylesheet" href="css/docbook.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.72.0"><link rel="start" href="manual.html" title="Apache OpenJPA User's Guide"><link rel="up" href="jpa_overview_mapping.html" title="Chapter&nbsp;12.&nbsp; Mapping Metadata"><link rel="prev" href="jpa_overview_mapping_unq.html" title="2.&nbsp; Unique Constraints"><link rel="next" href="jpa_overview_mapping_id.html" title="4.&nbsp; Identity Mapping"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3.&nbsp;
Column
</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jpa_overview_mapping_unq.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;12.&nbsp;
Mapping Metadata
</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="jpa_overview_mapping_id.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="jpa_overview_mapping_column"></a>3.&nbsp;
Column
</h2></div></div></div><a class="indexterm" name="d0e9642"></a><a class="indexterm" name="d0e9647"></a><p>
In the previous section, we saw that a <code class="classname">UniqueConstraint</code>
uses an array of column names. Field mappings, however, use full-fledged
<code class="classname">Column</code> annotations. Column annotations have the following
properties:
</p><div class="itemizedlist"><ul type="disc"><li><p>
<a class="indexterm" name="d0e9666"></a>
<code class="literal">String name</code>: The column name. Defaults to the field name.
</p></li><li><p>
<a class="indexterm" name="d0e9680"></a>
<code class="literal">String columnDefinition</code>: The database-specific column type
name. This property is only used by vendors that support creating tables from
your mapping metadata. During table creation, the vendor will use the value of
the <code class="literal">columnDefinition</code> as the declared column type. If no
<code class="literal">columnDefinition</code> is given, the vendor will choose an
appropriate default based on the field type combined with the column's length,
precision, and scale.
</p></li><li><p>
<a class="indexterm" name="d0e9700"></a>
<code class="literal">int length</code>: The column length. This property is typically
only used during table creation, though some vendors might use it to validate
data before flushing. <code class="literal">CHAR</code> and <code class="literal">VARCHAR</code>
columns typically default to a length of 255; other column types use the
database default.
</p></li><li><p>
<a class="indexterm" name="d0e9720"></a>
<code class="literal">int precision</code>: The precision of a numeric column. This
property is often used in conjunction with <code class="literal">scale</code> to form the
proper column type name during table creation.
</p></li><li><p>
<a class="indexterm" name="d0e9737"></a>
<code class="literal">int scale</code>: The number of decimal digits a numeric column can
hold. This property is often used in conjunction with <code class="literal">precision
</code> to form the proper column type name during table creation.
</p></li><li><p>
<a class="indexterm" name="d0e9754"></a>
<code class="literal">boolean nullable</code>: Whether the column can store null values.
Vendors may use this property both for table creation and at runtime; however,
it is never required. Defaults to <code class="literal">true</code>.
</p></li><li><p>
<a class="indexterm" name="d0e9771"></a>
<code class="literal">boolean insertable</code>: By setting this property to <code class="literal">
false</code>, you can omit the column from SQL <code class="literal">INSERT</code>
statements. Defaults to <code class="literal">true</code>.
</p></li><li><p>
<a class="indexterm" name="d0e9794"></a>
<code class="literal">boolean updatable</code>: By setting this property to <code class="literal">
false</code>, you can omit the column from SQL <code class="literal">UPDATE</code>
statements. Defaults to <code class="literal">true</code>.
</p></li><li><p>
<a class="indexterm" name="d0e9817"></a>
<code class="literal">String table</code>: Sometimes you will need to map fields to
tables other than the primary table. This property allows you specify that the
column resides in a secondary table. We will see how to map fields to secondary
tables later in the chapter.
</p></li></ul></div><p>
The equivalent XML element is <code class="literal">column</code>. This element has
attributes that are exactly equivalent to the <code class="classname"> Column</code>
annotation's properties described above:
</p><div class="itemizedlist"><ul type="disc"><li><p>
<code class="literal">name</code>
</p></li><li><p>
<code class="literal">column-definition</code>
</p></li><li><p>
<code class="literal">length</code>
</p></li><li><p>
<code class="literal">precision</code>
</p></li><li><p>
<code class="literal">scale</code>
</p></li><li><p>
<code class="literal">insertable</code>
</p></li><li><p>
<code class="literal">updatable</code>
</p></li><li><p>
<code class="literal">table</code>
</p></li></ul></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="jpa_overview_mapping_unq.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="jpa_overview_mapping.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="jpa_overview_mapping_id.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2.&nbsp;
Unique Constraints
&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;4.&nbsp;
Identity Mapping
</td></tr></table></div></body></html>