2.13.3. Column
In the previous section, we saw that a UniqueConstraint uses an array of column names.
Field mappings, however, use full-fledged Column annotations.
Column annotations have the following properties:
-
String name: The column name. Defaults to the field name. -
String columnDefinition: 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 thecolumnDefinitionas the declared column type. If nocolumnDefinitionis given, the vendor will choose an appropriate default based on the field type combined with the column’s length, precision, and scale. -
int length: The column length. This property is typically only used during table creation, though some vendors might use it to validate data before flushing.CHARandVARCHARcolumns typically default to a length of 255; other column types use the database default. -
int precision: The precision of a numeric column. This property is often used in conjunction withscaleto form the proper column type name during table creation. -
int scale: The number of decimal digits a numeric column can hold. This property is often used in conjunction withprecisionto form the proper column type name during table creation. -
boolean nullable: 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 totrue. -
boolean insertable: By setting this property tofalse, you can omit the column from SQLINSERTstatements. Defaults totrue. -
boolean updatable: By setting this property tofalse, you can omit the column from SQLUPDATEstatements. Defaults totrue. -
String table: 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.
The equivalent XML element is column.
This element has attributes that are exactly equivalent to the Column annotation’s properties described above:
-
name -
column-definition -
length -
precision -
scale -
insertable -
updatable -
table