liveBook · Manning

@Id

@Id is a persistence annotation that marks a field or property as the identifier of a persistent entity or object.

How 3 Manning books explain it

Spring in Action, Sixth Edition

@Id is a Spring Data JDBC annotation that marks a domain-property field as the persistent identity of an object.

How it is used
Marks the property that identifies a persisted domain object, row, or document.
How deep it goes
Explains placement, supported identifier examples, and namespace differences, but does not detail identifier-generation internals.
Examples
Uses TacoOrder, Taco, Ingredient, and IngredientRef classes with Long or String identity properties.
What you can do after
Apply the correct @Id variant to identity properties in Spring Data JDBC, JPA, or MongoDB domain types.

Read how Spring in Action, Sixth Edition explains @Id →

Java Persistence with Spring Data and Hibernate epub

@Id is the JPA annotation that marks a persistent property or field as an entity identifier.

How it is used
Marks the property that exposes database identity for JPA entities and Spring Data JDBC aggregates.
How deep it goes
Explains required identifiers, default ID mapping, field access, generated values, and explicit column mapping without covering composite identifiers.
Examples
Uses generated Long ids on Item and an explicitly mapped ID field on a Spring Data JDBC User.
What you can do after
Apply it via JPA or Spring Data JDBC to map entity identity and support identifier-based persistence and lookup.

Read how Java Persistence with Spring Data and Hibernate epub explains @Id →

Spring Start Here, Second Edition

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

How it is used
Marks the model field Spring Data JDBC uses to identify a table’s primary key.
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.

Read how Spring Start Here, Second Edition explains @Id →

Also covered in

What to know first

Related concepts

Questions about @Id

What is @Id?

@Id is a persistence annotation that marks a field or property as the identifier of a persistent entity or object.

Which Manning books explain @Id?

Spring in Action, Sixth Edition, Java Persistence with Spring Data and Hibernate epub and Spring Start Here, Second Edition.

What should I know before learning @Id?

Manning books that teach @Id usually introduce database table first.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.