= EntityState _(enum)_
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Enumerates the state of an entity.

== API

[source,java]
.EntityState.java
----
enum EntityState {
  NOT_PERSISTABLE     // <.>
  ATTACHED     // <.>
  ATTACHED_NO_OID     // <.>
  DETACHED     // <.>
  HOLLOW     // <.>
  TRANSIENT_OR_REMOVED     // <.>
  REMOVED     // <.>
  boolean isPersistable()     // <.>
  boolean isAttached()     // <.>
  boolean isAttachedNoOid()     // <.>
  boolean isDetached()     // <.>
  boolean isHollow()     // <.>
  boolean isTransientOrRemoved()     // <.>
  boolean isRemoved()     // <.>
  boolean isAttachedOrRemoved()
}
----

<.> xref:#NOT_PERSISTABLE[NOT_PERSISTABLE]
+
--
Object with this state is not an entity (for example it might be a view model, value type or a domain service).
--
<.> xref:#ATTACHED[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.
--
<.> xref:#ATTACHED_NO_OID[ATTACHED_NO_OID]
+
--
Is attached, has no OID yet. On pre-store.
--
<.> xref:#DETACHED[DETACHED]
+
--
Is detached, hence (per definition) has an OID.
--
<.> xref:#HOLLOW[HOLLOW]
+
--
JDO specificObject with this state is an entity that no longer attached to a persistence session and cannot be re-attached. In other words: changes to the entity will _not_ be tracked nor flushed back to the database.
--
<.> xref:#TRANSIENT_OR_REMOVED[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.
--
<.> xref:#REMOVED[REMOVED]
+
--
JDO specificNot supported by JPA. (Cannot distinguish between TRANSIENT and REMOVED.)
--
<.> xref:#isPersistable_[isPersistable()]
+
--
Object is an entity, hence is persistable to the database.
--
<.> xref:#isAttached_[isAttached()]
<.> xref:#isAttachedNoOid_[isAttachedNoOid()]
<.> xref:#isDetached_[isDetached()]
<.> xref:#isHollow_[isHollow()]
<.> xref:#isTransientOrRemoved_[isTransientOrRemoved()]
<.> xref:#isRemoved_[isRemoved()]

== Members

[#NOT_PERSISTABLE]
=== NOT_PERSISTABLE

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

[#ATTACHED]
=== 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]
=== ATTACHED_NO_OID

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

[#DETACHED]
=== DETACHED

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

Supported by both JDO and JPA. However, historically never used by the framework for JDO.

[#HOLLOW]
=== HOLLOW

JDO specificObject with this state is an entity that no longer attached to a persistence session and cannot be re-attached. In other words: changes to the entity will _not_ be tracked nor flushed back to the database.

JDO distinguishes between DETACHED and HOLLOW, by virtue of _javax.jdo.option.detachAllOnCommit=false_ .

(Unfortunately, we have not found a way to recover _OIDs_ from _hollow_ entities, as used for serialization post commit. We have instead implemented a workaround using the `DnStateManagerForHollow` class).

[#TRANSIENT_OR_REMOVED]
=== 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]
=== REMOVED

JDO specificNot supported by JPA. (Cannot distinguish between TRANSIENT and REMOVED.)

[#isPersistable_]
=== isPersistable()

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

[#isAttached_]
=== isAttached()

[#isAttachedNoOid_]
=== isAttachedNoOid()

[#isDetached_]
=== isDetached()

[#isHollow_]
=== isHollow()

[#isTransientOrRemoved_]
=== isTransientOrRemoved()

[#isRemoved_]
=== isRemoved()
