一个持久化类的实例可能处于三种不同状态中的某一种。 这三种状态的定义则与所谓的持久化上下文(persistence context)有关。 Hibernate的Session
对象就是这个所谓的持久化上下文:
该实例从未与任何持久化上下文关联过。它没有持久化标识(相当于主键值)。
实例目前与某个持久化上下文有关联。 它拥有持久化标识(相当于主键值),并且可能在数据库中有一个对应的行。 对于某一个特定的持久化上下文,Hibernate保证持久化标识与Java标识(其值代表对象在内存中的位置)等价。
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, perhaps, a corresponding row in the database. For detached instances, Hibernate makes no guarantees about the relationship between persistent identity and Java identity.