Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Basic Mappings/Column"

m
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{EclipseLink_UserGuide
 
{{EclipseLink_UserGuide
 
|info=y
 
|info=y
|toc=n}}
+
|toc=n
 
+
|eclipselink=y
THIS PAGE IS IN PROGRESS...
+
|eclipselinktype=JPA
 +
|api=y
 +
|apis=
 +
* [http://www.eclipse.org/eclipselink/api/latest/javax/persistence/Column.html @Column]
 +
}}
  
=@Column=
+
= @Column =
  
Use the Column annotation to specify a mapped column for a persistent property or field.
+
Use the <tt>@Column</tt> annotation to specify a mapped column for a persistent property or field. If no <tt>Column</tt> annotation is specified, the default values, as shown in the table below, apply.
  
 
.{{EclipseLink_Spec
 
.{{EclipseLink_Spec
|section=Section 11.1.9 "Column Annotation"}}
+
|section=Section 11.1.9 "Column Annotation"}}  
  
 
+
<br> {{EclipseLink_AttributeTable
The following  example shows how to use the <tt>@Column</tt> annotation to ....
+
|caption=@Column Annotation Attributes
 
+
 
+
{{EclipseLink_AttributeTable
+
|caption=The <tt>@Column</tt> annotation has the following attributes:
+
 
|content=
 
|content=
 
<tr>
 
<tr>
 
  <td>'''<tt>name</tt>'''</td>
 
  <td>'''<tt>name</tt>'''</td>
  <td>feh</td>
+
  <td>The name of the column.</td>
  <td>feh</td>
+
  <td>The property or field
  <td>feh</td>
+
name.</td>
 +
  <td>No</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
  <td>'''<tt>unique</tt>'''</td>
 
  <td>'''<tt>unique</tt>'''</td>
  <td>feh</td>
+
  <td>Whether the column is a unique key. This is a shortcut for the UniqueConstraint annotation at the table level and is useful for when the unique key constraint corresponds to only a single column. This constraint applies in addition to any constraint entailed by primary key mapping and to constraints specified at the table level.</td>
  <td>feh</td>
+
  <td><tt>false</tt></td>
  <td>feh</td>
+
  <td>No</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
  <td>'''<tt>nullable</tt>'''</td>
 
  <td>'''<tt>nullable</tt>'''</td>
  <td>feh</td>
+
  <td>Whether the database column is nullable.</td>
  <td>feh</td>
+
  <td><tt>true</tt></td>
  <td>feh</td>
+
  <td>No</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
  <td>'''<tt>insertable</tt>'''</td>
 
  <td>'''<tt>insertable</tt>'''</td>
  <td>feh</td>
+
  <td>Whether the column is included in SQL INSERT statements generated by the persistence
  <td>feh</td>
+
provider.</td>
  <td>feh</td>
+
  <td><tt>true</tt></td>
 +
  <td>No</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
  <td>'''<tt>updatable</tt>'''</td>
 
  <td>'''<tt>updatable</tt>'''</td>
  <td>feh</td>
+
  <td>Whether the column is included in SQL UPDATE statements generated by the persistence provider.</td>
  <td>feh</td>
+
  <td><tt>true</tt></td>
  <td>feh</td>
+
  <td>No</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
  <td>'''<tt>columnDefinition</tt>'''</td>
 
  <td>'''<tt>columnDefinition</tt>'''</td>
  <td>feh</td>
+
  <td>The SQL fragment that is used when generating the DDL for the column.</td>
  <td>feh</td>
+
  <td>Generated DDL to create a column of the inferred type.</td>
  <td>feh</td>
+
  <td>No</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
  <td>'''<tt>table</tt>'''</td>
 
  <td>'''<tt>table</tt>'''</td>
  <td>feh</td>
+
  <td>The name of the table that contains the column. If absent the column is assumed to be in the
  <td>feh</td>
+
primary table for the mapped object.</td>
  <td>feh</td>
+
  <td>Column is in primary table.</td>
 +
  <td>No</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
  <td>'''<tt>length</tt>'''</td>
 
  <td>'''<tt>length</tt>'''</td>
  <td>feh</td>
+
  <td>The column length. (Applies only if a string-valued column is used.)</td>
  <td>feh</td>
+
  <td>255</td>
  <td>feh</td>
+
  <td>No</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
 
  <td>'''<tt>precision</tt>'''</td>
 
  <td>'''<tt>precision</tt>'''</td>
  <td>feh</td>
+
  <td>The precision for a decimal (exact numeric) column. (Applies only if a decimal column is used.)</td>
  <td>feh</td>
+
  <td><tt>0</tt> (Value must be set by developer.)</td>
  <td>feh</td>
+
  <td>No</td>
 
</tr>
 
</tr>
 +
<tr>
 +
<td>'''<tt>scale</tt>'''</td>
 +
<td>The scale for a decimal (exact numeric) column. (Applies only if a decimal column is used.)
 +
</td>
 +
<td><tt>0</tt></td>
 +
<td>No</td>
 +
</tr>
 +
}}
  
  
}}
+
The following example shows how to use the <tt>@Column</tt> annotation, with values to override the defaults for <tt>updatable</tt>, <tt>precision</tt>, and <tt>scale</tt>.
''''' Usage of the @Column Annotation'''''
+
 
 +
======''Example: @Column Annotation''======
 
<source lang="java">
 
<source lang="java">
 
@Column(name="ORDER_COST", updatable=false, precision=12, scale=2)
 
@Column(name="ORDER_COST", updatable=false, precision=12, scale=2)
 
public BigDecimal getCost() { return cost; }
 
public BigDecimal getCost() { return cost; }
</source>
+
</source>  
  
 
{{EclipseLink_JPA
 
{{EclipseLink_JPA

Latest revision as of 15:27, 27 October 2011

EclipseLink JPA

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

Elug api package icon.png Key API


@Column

Use the @Column annotation to specify a mapped column for a persistent property or field. If no Column annotation is specified, the default values, as shown in the table below, apply.

.
Elug javaspec icon.gif

For more information, see Section 11.1.9 "Column Annotation" in the JPA Specification.


@Column Annotation Attributes
Attribute Description Default Required?
name The name of the column. The property or field name. No
unique Whether the column is a unique key. This is a shortcut for the UniqueConstraint annotation at the table level and is useful for when the unique key constraint corresponds to only a single column. This constraint applies in addition to any constraint entailed by primary key mapping and to constraints specified at the table level. false No
nullable Whether the database column is nullable. true No
insertable Whether the column is included in SQL INSERT statements generated by the persistence provider. true No
updatable Whether the column is included in SQL UPDATE statements generated by the persistence provider. true No
columnDefinition The SQL fragment that is used when generating the DDL for the column. Generated DDL to create a column of the inferred type. No
table The name of the table that contains the column. If absent the column is assumed to be in the primary table for the mapped object. Column is in primary table. No
length The column length. (Applies only if a string-valued column is used.) 255 No
precision The precision for a decimal (exact numeric) column. (Applies only if a decimal column is used.) 0 (Value must be set by developer.) No
scale The scale for a decimal (exact numeric) column. (Applies only if a decimal column is used.) 0 No


The following example shows how to use the @Column annotation, with values to override the defaults for updatable, precision, and scale.

Example: @Column Annotation
@Column(name="ORDER_COST", updatable=false, precision=12, scale=2)
public BigDecimal getCost() { return cost; }

Eclipselink-logo.gif
Version: DRAFT
Other versions...