日期:2014-05-16  浏览次数:20451 次

HIbernate符合Java习惯的关系数据库持久化之实例状态

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:

瞬态(transient)

The instance is not associated with any persistence context. It has no persistent identity or primary key value.

持久化(persistent)

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.

脱管(detached)

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.