liveBook · Manning

@Id

As explained in Spring Start Here, Second Edition

The @Id annotation identifies the property or field that uniquely identifies a persistent entity.

In Spring Data JDBC, @Id marks the model field that maps to a table’s primary key, identifying the key Spring Data uses for operations such as retrieval. section 14.3

Listing 14.3 The Account class that models the account table records
public class Account {
 
  @Id   #A
  private long id;
 
  private String name;
  private BigDecimal amount;
 
  // Omitted getters and setters
 
}

The Account model marks its id field with @Id. section 14.3

How Spring Start Here, Second Edition covers it

How deep it goes
Defines the annotation’s role and shows a model example, but does not explain annotation internals.
Examples
Shows @Id on the id field of an Account model mapped to an account table.
What you can do after
Understand how to mark a Java model field as its table’s primary key.
How it connects
Connects Spring Data JDBC and primary keys with entity models and CrudRepository.

Also explained in

Compare how 3 books explain @Id →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.