= 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     // <.>
  PERSISTABLE_ATTACHED     // <.>
  PERSISTABLE_DETACHED     // <.>
  PERSISTABLE_REMOVED     // <.>
  PERSISTABLE_ATTACHED_NO_OID     // <.>
  PERSISTABLE_DETACHED_WITH_OID     // <.>
  boolean isPersistable()     // <.>
  boolean isAttached()     // <.>
  boolean isDetached()     // <.>
  boolean isRemoved()     // <.>
  boolean isAttachedNoOid()     // <.>
  boolean isDetachedCannotReattach()
  boolean isAttachedOrRemoved()     // <.>
  boolean isJpaSpecificDetachedWithOid()     // <.>
  boolean hasOid()
}
----

<.> 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:#PERSISTABLE_ATTACHED[PERSISTABLE_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:#PERSISTABLE_DETACHED[PERSISTABLE_DETACHED]
+
--
Object with this state is an entity but that is detached from a persistence session, in other words changes to the entity will _not_ be flushed back to the database.JDO specifics:
--
<.> xref:#PERSISTABLE_REMOVED[PERSISTABLE_REMOVED]
+
--
Object with this state is an entity that has been removed from the database. Objects in this state may no longer be interacted with.
--
<.> xref:#PERSISTABLE_ATTACHED_NO_OID[PERSISTABLE_ATTACHED_NO_OID]
+
--
Is attached, has no OID yet. On pre-store.
--
<.> xref:#PERSISTABLE_DETACHED_WITH_OID[PERSISTABLE_DETACHED_WITH_OID]
+
--
JPA specific. Is detached, but has an OID.
--
<.> xref:#isPersistable_[isPersistable()]
+
--
Object is an entity so is _potentially_ persistable ot the database.
--
<.> xref:#isAttached_[isAttached()]
+
--
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:#isDetached_[isDetached()]
+
--
Object with this state is an entity but that is detached from a persistence session, in other words changes to the entity will _not_ be flushed back to the database.
--
<.> xref:#isRemoved_[isRemoved()]
+
--
Object with this state is an entity that has been removed from the database. Objects in this state may no longer be interacted with.
--
<.> xref:#isAttachedNoOid_[isAttachedNoOid()]
<.> xref:#isAttachedOrRemoved_[isAttachedOrRemoved()]
+
--
[WARNING]
====
[red]#_deprecated:_#

not supported by JPA
====
--
<.> xref:#isJpaSpecificDetachedWithOid_[isJpaSpecificDetachedWithOid()]

== 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).

[#PERSISTABLE_ATTACHED]
=== PERSISTABLE_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.

[#PERSISTABLE_DETACHED]
=== PERSISTABLE_DETACHED

Object with this state is an entity but that is detached from a persistence session, in other words changes to the entity will _not_ be flushed back to the database.JDO specifics:

JDO distinguishes between DETACHED and HOLLOW, where we are using HOLLOW here, by virtue of _datanucleus.detachAllOnCommit=false_ .

(Unfortunately, we have not found a way to recover _OIDs_ from _hollow_ entities, as used for serialization post commit. So a workaround is in place with DnStateManagerForHollow.)

[#PERSISTABLE_REMOVED]
=== PERSISTABLE_REMOVED

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

[#PERSISTABLE_ATTACHED_NO_OID]
=== PERSISTABLE_ATTACHED_NO_OID

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

[#PERSISTABLE_DETACHED_WITH_OID]
=== PERSISTABLE_DETACHED_WITH_OID

JPA specific. Is detached, but has an OID.

[#isPersistable_]
=== isPersistable()

Object is an entity so is _potentially_ persistable ot the database.

[#isAttached_]
=== isAttached()

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.

[#isDetached_]
=== isDetached()

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

[#isRemoved_]
=== isRemoved()

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

Only supported by JDO. Will always return false with JPA.

[#isAttachedNoOid_]
=== isAttachedNoOid()

[#isAttachedOrRemoved_]
=== isAttachedOrRemoved()

[WARNING]
====
[red]#_deprecated:_#

not supported by JPA
====

[#isJpaSpecificDetachedWithOid_]
=== isJpaSpecificDetachedWithOid()
