Skip to main content
Jump to: navigation, search

EclipseLink/UserGuide/JPA/Basic JPA Development/Entities/Ids/Id


Use the @Id annotation to designate one or more persistent fields or properties as the entity's primary key.

For each entity, you must designate at least one of the following:

Note: The last option in the preceding list – @Id and @IdClass combination – is applicable to composite primary key configuration.

The @Id annotation does not have attributes.

By default, EclipseLink persistence provider chooses the most appropriate primary key generator (see @GeneratedValue) and is responsible for managing primary key values: you do not need to take any further action if you are satisfied with the persistence provider's default key generation mechanism.

This example shows how to use this annotation to designate the persistent field empID as the primary key of the Employee table.

Usage of @Id Annotation

 public class Employee implements Serializable {
     private int empID;

The @Id annotation supports the use of EclipseLink converters (see Using EclipseLink JPA Converters).

For more information and examples, see Section 9.1.8 "Id Annotation" of the JPA Specification.

Version: DRAFT
Other versions...

Back to the top