Use of @Id annotation.

@Id is a JPA annotation that marks a field or property on an entity class as its primary key, telling the persistence provider which value uniquely identifies each row and how to track and manage that entity's identity.

Key Points: • Every JPA entity must have exactly one field or property annotated with @Id. • @Id is commonly paired with @GeneratedValue to let the database or persistence provider auto-generate the value on insert. • JPA uses the @Id field to determine entity identity for equals()/caching purposes and to decide whether save() should insert or update. • For composite keys, @Id alone isn't enough; you'd use @EmbeddedId or @IdClass instead.

Example: An Employee entity's employeeId field is annotated with @Id so JPA knows that column is the primary key used to look up, update, and uniquely identify each employee record.

Code Example:

@Entity
public class Employee {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long employeeId;

    private String name;
}

Interview Tip: A concise interview answer is:

"@Id marks the field that JPA treats as the entity's primary key, which it uses to track identity, decide whether save() inserts or updates, and generate the underlying SQL. I usually pair it with @GeneratedValue so the database or provider auto-generates the key value on insert."