# ID mapping

Use an ID Mapping to specify the primary key of an entity. ID mappings may be used with a Entity or Mapped superclass. Each Entity must have an ID mapping.

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

2. Right click the filed and then select Map as > ID. The JPA Details view (for attributes) displays the properties for the selected.

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

   Property | Description | Default
   --- | --- | ---
   Entity Mapping Hyperlink | Defines this mapping as an ID Mapping. This field corresponds to the `@Id` annotation. | ID
   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.
   Table | The database table mapped to the entity attribute. | By default, the Table is assumed to be identical to the table associated with the entity.
   Temporal | Specifies the type of data. See "Temporal" for details. Date Time Timestamp |

4. Use this table to complete the fields in Primary Key Generation information area in the JPA Details view.

   Property | Description | Default
   --- | --- | ---
   Primary Key Generation | These fields define how the primary key is generated. |
   Strategy | See "Primary Key Generation" for details. Auto Sequence Identity Table | Auto
   Generator Name | Name of the primary key generator specified in the Strategy |

Additional fields will appear in the Primary Key Generation information area, depending on the selected Strategy. See "JPA Details view (for attributes)" for additional information.

Eclipse adds the following annotations to the field:

    @Id
    @Column(name="<COLUMN_NAME>", table="<TABLE_NAME>", insertable=<INSERTABLE>,
        updatable=<UPDATABLE>)
    @Temporal(<TEMPORAL>)
    @GeneratedValue(strategy=GeneratorType.<STRATEGY>, generator="<GENERATOR_NAME>")@TableGenerator(name="<TABLE_GENERATOR_NAME>", table = "<TABLE_GENERATOR_TABLE>",
        pkColumnName = "<TABLE_GENERATOR_PK>",
        valueColumnName = "<TABLE_GENERATOR_VALUE_COLUMN>",
        pkColumnValue = "<TABLE_GENERATOR_PK_COLUMN_VALUE>")@SequenceGenerator(name="<SEQUENCE_GENERATOR_NAME>",
        sequenceName="<SEQUENCE_GENERATOR_SEQUENCE>")

Mapping an entity

JPA Structure view
JPA Details view (for attributes)

Understanding OR mappings
Understanding EJB 3.0 Java Persistence API