| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>3. Column</title><base href="display"><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><link rel="home" href="manual.html" title="Apache OpenJPA 2.4 User's Guide"><link rel="up" href="jpa_overview_mapping.html" title="Chapter 13. Mapping Metadata"><link rel="prev" href="jpa_overview_mapping_unq.html" title="2. Unique Constraints"><link rel="next" href="jpa_overview_mapping_id.html" title="4. 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. |
| Column |
| </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jpa_overview_mapping_unq.html">Prev</a> </td><th width="60%" align="center">Chapter 13. |
| Mapping Metadata |
| </th><td width="20%" align="right"> <a accesskey="n" href="jpa_overview_mapping_id.html">Next</a></td></tr></table><hr></div><div class="section" title="3. Column"><div class="titlepage"><div><div><h2 class="title" style="clear: both" id="jpa_overview_mapping_column">3. |
| Column |
| </h2></div></div></div> |
| |
| <a class="indexterm" name="d5e5512"></a> |
| <a class="indexterm" name="d5e5515"></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 class="itemizedlist" type="disc"><li class="listitem"> |
| <p> |
| <a class="indexterm" name="d5e5525"></a> |
| <code class="literal">String name</code>: The column name. Defaults to the field name. |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <a class="indexterm" name="d5e5532"></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 class="listitem"> |
| <p> |
| <a class="indexterm" name="d5e5541"></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 class="listitem"> |
| <p> |
| <a class="indexterm" name="d5e5550"></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 class="listitem"> |
| <p> |
| <a class="indexterm" name="d5e5558"></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 class="listitem"> |
| <p> |
| <a class="indexterm" name="d5e5566"></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 class="listitem"> |
| <p> |
| <a class="indexterm" name="d5e5574"></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 class="listitem"> |
| <p> |
| <a class="indexterm" name="d5e5584"></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 class="listitem"> |
| <p> |
| <a class="indexterm" name="d5e5594"></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 class="itemizedlist" type="disc"><li class="listitem"> |
| <p> |
| <code class="literal">name</code> |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <code class="literal">column-definition</code> |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <code class="literal">length</code> |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <code class="literal">precision</code> |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <code class="literal">scale</code> |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <code class="literal">insertable</code> |
| </p> |
| </li><li class="listitem"> |
| <p> |
| <code class="literal">updatable</code> |
| </p> |
| </li><li class="listitem"> |
| <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> </td><td width="20%" align="center"><a accesskey="u" href="jpa_overview_mapping.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="jpa_overview_mapping_id.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2. |
| Unique Constraints |
| </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> 4. |
| Identity Mapping |
| </td></tr></table></div></body></html> |