Hibernate 学习笔记 - Lifecycle 1

本文总结了Hibernate中的三个生命周期状态:Transient、Persistent和Detached。理解这些状态有助于深入掌握Hibernate的工作原理。Transient状态下,对象与数据库无关联;Persistent状态时,Session管理对象与数据库的同步;Detached状态下,对象虽在数据库中有记录,但修改不会同步到数据库。

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

这篇文章是关于Hibernate的三个Life cycle state的总结。 了解清楚会对hibernate的工作原理有很好的认识。

any instance of object only can be three states:

  • Transient
  • persistent
  • detached

Transient :

Hibernate not manage transient object.

In transient state, POJO is communication with the client code only, no any connection with database



Persistent

in Persistent state, a Session object created to manage the persistence of the Java object and database,

change of both side will keep up-to-date.


Detached

In Detached state, POJO still has a presentation in the database but the change of POJO will not make database updated, and vice versa.

it's created by session.close() or session.evict()

detached state can be back to persistence state by connecting to a new session. it happens when callingload(), refresh(), merge(), update(), orsave() methods on the new session with a reference to the detached object.




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值