日期:2014-05-16 浏览次数:20472 次
An instance of a persistent class can be in one of three different states. These states are defined in relation to a persistence context
. The Hibernate Session
object is the persistence context. The three different states are as follows:
The instance is not associated with any persistence context. It has no persistent identity or primary key value.
The instance is currently associated with a persistence context. It has a persistent identity (primary key value) and can have a corresponding row in the database. For a particular persistence context, Hibernate guarantees that persistent identity is equivalent to Java identity in relation to the in-memory location of the object.
The instance was once associated with a persistence context, but that context was closed, or the instance was serialized to another process. It has a persistent identity and can have a corresponding row in the database. For detached instances, Hibernate does not guarantee the relationship between persistent identity and Java identity.