12.3. Column
Prev | Chapter 12. Mapping Metadata | Next

## 12.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 the `columnDefinition` as the declared column type. If no `columnDefinition` is 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. `CHAR` and `VARCHAR` columns 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 with `scale` to 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 with `precision` to 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 to `true`.

- `boolean insertable`: By setting this property to `false`, you can omit the column from SQL `INSERT` statements. Defaults to `true`.

- `boolean updatable`: By setting this property to `false`, you can omit the column from SQL `UPDATE` statements. Defaults to `true`.

- `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`

Prev | Up | Next
12.2. Unique Constraints | Home | 12.4. Identity Mapping