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

本文详细解释了对象在三种不同持久化状态中的含义:瞬态、持久化和脱管。这些状态与Hibernate会话(即持久化上下文)密切相关,并探讨了每种状态下实例的特点及其与数据库的关系。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值