Interview questions
Question 240 of 254
FreeWhat are the four entity states in JPA/Hibernate — transient, persistent, detached, and removed?
Hibernate & JPA Internals
Transient: a plain new object created via `new`, not associated with any persistence context and not saved. Persistent (managed): the entity is tracked by the current persistence context — any change to it is automatically detected (dirty checking) and flushed to the database. Detached: the entity was persistent but its persistence context has since closed (e.g., the transaction ended) — it still holds data but changes to it are no longer tracked or auto-saved. Removed: the entity is scheduled for deletion within the current persistence context, deleted from the database on the next flush.
Intermediate5 min

