EntityState (enum)

Enumerates the state of an entity.

API

EntityState.java
enum EntityState {
  NOT_PERSISTABLE     (1)
  SNAPSHOT     (2)
  SNAPSHOT_NO_OID     (3)
  ATTACHED     (4)
  ATTACHED_NO_OID     (5)
  DETACHED     (6)
  TRANSIENT_OR_REMOVED     (7)
  REMOVED     (8)
  boolean isPersistable()     (9)
  boolean isAttached()     (10)
  boolean isAttachedNoOid()     (11)
  boolean isDetached()     (12)
  boolean isTransientOrRemoved()
  boolean isRemoved()     (13)
  boolean isAttachedOrRemoved()
}
1 NOT_PERSISTABLE

Object with this state is not an entity (for example it might be a view model, value type or a domain service).

2 SNAPSHOT

Object with this state is an entity that has no session.

3 SNAPSHOT_NO_OID

Object with this state is an entity that has no session and has no OID yet. On pre-store.

4 ATTACHED

Object with this state is an entity that is attached to a persistence session, in other words changes to the entity will be flushed back to the database.

5 ATTACHED_NO_OID

Is attached, has no OID yet. On pre-store.

6 DETACHED

Is detached, hence (per definition) has an OID.

7 TRANSIENT_OR_REMOVED

Object with this state is an entity that is transient or has been removed from the database. Objects in this state may no longer be interacted with.

8 REMOVED

Set by the framework after entity removal.

9 isPersistable()

Object is an entity, hence is persistable to the database.

10 isAttached()
11 isAttachedNoOid()
12 isDetached()
13 isRemoved()

Members

NOT_PERSISTABLE

Object with this state is not an entity (for example it might be a view model, value type or a domain service).

SNAPSHOT

Object with this state is an entity that has no session.

SNAPSHOT_NO_OID

Object with this state is an entity that has no session and has no OID yet. On pre-store.

ATTACHED

Object with this state is an entity that is attached to a persistence session, in other words changes to the entity will be flushed back to the database.

ATTACHED_NO_OID

Is attached, has no OID yet. On pre-store.

DETACHED

Is detached, hence (per definition) has an OID.

TRANSIENT_OR_REMOVED

Object with this state is an entity that is transient or has been removed from the database. Objects in this state may no longer be interacted with.

REMOVED

Set by the framework after entity removal.

However, detecting an entity’s state in the JPA context will never yield #REMOVED .

isPersistable()

Object is an entity, hence is persistable to the database.

isAttached()

isAttachedNoOid()

isDetached()

isRemoved()