JPA entities can be new, managed, detached, or removed. These states describe an object’s relationship to a persistence context—not simply whether a database row exists. In particular, an entity can be managed before its insert reaches the database, and a removed entity can remain in the context while its deletion is pending.
What the four entity states mean
Jakarta Persistence defines entity lifecycle operations relative to a persistence context. Hibernate uses closely related terms: it commonly calls a new entity transient and a managed entity persistent. The labels differ, but the central question is the same: is this Java object associated with the current persistence context?
As an Amazon Associate I earn from qualifying purchases.
| State | Identity and context | What happens to changes |
|---|---|---|
| New (Hibernate: transient) | No persistent identity and not associated with a persistence context. | Changes are ordinary in-memory changes. Calling persist() makes the entity managed; an insert may wait until flush or commit. |
| Managed (Hibernate: persistent) | Has persistent identity and is associated with the current persistence context. | The context tracks persistent-state changes and synchronizes them when it flushes. An insert or update may still be pending. |
| Detached | Has persistent identity but is no longer associated with the context. | Changes are not automatically tracked by the context from which it became detached. merge() copies state to a managed instance and returns that instance. |
| Removed | Has persistent identity, remains associated with the context, and is marked for deletion. | Deletion is synchronized through flushing, typically at or before transaction commit. |
The Jakarta Persistence 4.0 milestone 4 specification defines a managed entity as one with persistent identity that is currently associated with a persistence context. The milestone status matters: this is an M4 specification, not a claim about a final 4.0 release. See Jakarta Persistence 4.0 M4, section 3.6. For Hibernate’s terminology and context behavior, see the Hibernate ORM User Guide; it is a rolling guide, so consult the documentation for the Hibernate version used by your application when relying on implementation-specific behavior.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →How entities move between states
New to managed with persist()
A newly constructed object is new (transient in Hibernate terminology). Calling persist(entity) on it makes it managed by the applicable persistence context. That lifecycle change does not promise that an SQL INSERT runs at that exact call. The persistence context synchronizes its pending work when it flushes, which can occur before or during transaction completion depending on the circumstances.
#1 Best Overall
Managed to detached
An entity becomes detached when it is no longer associated with the persistence context. Detachment can result from an explicit detach operation or from a context boundary such as clearing or closing the context. Once detached, edits to the Java object are not automatically tracked by that former context.
Detached to managed with merge()
merge(detachedEntity) copies the detached entity’s state into a managed instance and returns that instance. Do not assume the object passed to merge() itself becomes managed; use the returned value for subsequent work that needs the managed object. For detached input, Jakarta Persistence describes the returned instance as having the same persistent identity and state but a distinct Java object identity. See the specification’s merge semantics.
Managed to removed with remove()
Calling remove(entity) on a managed entity marks it for deletion. The object remains associated with the persistence context in the removed state until synchronization and lifecycle processing complete. The delete is not necessarily sent to the database at the moment remove() is called.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesWhy flush and commit matter
A persistence context tracks changes in memory and synchronizes them with the database through a flush. Consequently, the four states are not a direct report of which SQL statements have already run:
Rank #3
- A managed entity may be awaiting its initial insert.
- Edits to a managed entity may be awaiting an update.
- A removed entity may be awaiting a delete.
Flush is the synchronization point; transaction commit is a transaction boundary, not a guarantee that every lifecycle method executed SQL immediately. The precise timing can depend on the persistence provider, transaction setup, and flush behavior. Jakarta Persistence’s lifecycle and synchronization rules are set out in section 3.6 of the 4.0 M4 specification.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.What to check when debugging an entity
- New or transient: Was the object constructed but not persisted?
- Managed or persistent: Is it associated with the current persistence context, so that context can track its changes?
- Detached: Did it outlive, or get separated from, the context that managed it? If you merge it, are you using the returned object?
- Removed: Was it marked for deletion while still managed, with database synchronization still pending?
Also check relationship mappings before expecting lifecycle operations to propagate to associated entities. Cascading occurs only where the mapping includes the relevant cascade type; it is not automatic for every association. See the Jakarta Persistence specification for the operation and cascade rules.
Quick Recap
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.




