# 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.

   JPA Details, ID mapping

3. Complete each field in the ID Mapping area.

4. Use the Primary Key Generation area to specify the strategy to use for generating primary keys.

   JPA Details, Primary key generation

5. Complete each field in the Primary Key Generation information area.

6. Complete the remaining areas in the JPA Details view (for attributes).

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>")

Related tasks

- Mapping an entity

Related references

- JPA Structure view

- JPA Details view (for attributes)

- Primary Key Generation information

- Converters

- Type information

Related concepts

- Understanding OR mappings

- Understanding Java Persistence API