JPA id annotation

The @Id annotation is used to specify the primary key of an entity. The field or property to which the Id annotation is applied should be one of the following types:
1. Any Java primitive type
2. Any primitive wrapper type.
3. String
4. java.util.Date
5. java.sql.Date
6. java.math.BigDecimal
7. java.math.BigInteger

It is contained in the javax.persistence package. The mapped column for the primary key of the entity is assumed to be the primary key of the primary table. If no Column annotation is specified, the primary key column name is assumed to be the name of the primary key property or field.

JPA field access strategy example:

JPA field access strategy specify that annotation is applied to a field instead of getter method.
Example:

@Id
private Long studentId;

JPA property access strategy example:

JPA property access strategy specify that annotation is applied to getter method instead of the field.
Note: JPA property access gives the flexibility to modify the value of actual value set in id field if required.
Example:

@Id
public Long getStudentId()
{
  return studentId;
}