# Version mapping

Use a Version Mapping to specify the field used for optimistic locking. If the entity is associated with multiple tables, you should use a version mapping only with the primary table. You should have only a single version mapping per persistent entity. Version mappings may be used only with the following attribute types:

- `int`

- `Integer`

- `short, Short`

- `long, Long`

- `Timestamp`

To create a version mapping:

1. In the JPA Structure view, select the field to map.

2. Right-click the field and then select Map As > Version. The JPA Details view (for attributes) displays the properties for the selected.

3. Use this table to complete the remaining fields in the JPA Details view.

   Property | Description | Default
   --- | --- | ---
   Mapped Entity Hyperlink | Defines the mapping as Version. This corresponds to the `@Version` annotation. | Version
   Column | The database column mapped to the entity attribute. See "Column" for details. | By default, the Column is assumed to be named identically to the attribute and always included in the `INSERT` and `UPDATE` statements.
   Table | Name of the database table. This must be the primary table associated with the attribute's entity. |
   Temporal | Specifies the type of data. See "Temporal" for details. Date Time Timestamp |

Eclipse adds the following annotations to the field:

    @Version
    @Column(table="<COLUMN_TABLE>", name="<COLUMN_NAME>")

Mapping an entity

JPA Structure view
JPA Details view (for attributes)

Understanding OR mappings
Understanding EJB 3.0 Java Persistence API