Card 07/ 07
Recap: The JPA Entity Lifecycle
Four states, the operations between them, insert timing, detached changes, and refresh or clear.
The JPA entity lifecycle comes down to the five ideas below, each listed with the card that covers it.
| The idea | Where |
|---|---|
| An entity is transient, managed, detached or removed, and only managed changes are written | JPA Entity States: Transient, Managed, Detached and Removed |
contains() shows the real state; merge() returns a different, managed object | Tracing One Entity Through the JPA Lifecycle |
With IDENTITY ids, persist() inserts at once; with SEQUENCE, at flush | When persist() Inserts: IDENTITY vs SEQUENCE Ids |
| Changes to a detached entity are never written | Detached Entities: Changes That Never Reach the Database |
refresh() reloads one entity; clear() detaches all and reads nothing | refresh() vs clear() in JPA |
When a JPA change goes missing, or appears when you did not expect it, the entity's state is the first thing to check.
← → move through sections and cards