Hibernate学习笔记:对象生命周期

学到这里我想谈一下自己的感受:在hibernate的世界里,要转换一下思维方式,那就是面向对象;在使用hibernate的时候,要忘记关系表,头脑中存在的就是

对象以及对象之间的关系.当配置文件编写完毕之后,对象和对象之间的关系也就确定了.由hibernate掌握所有对象的生命周期.
hibernate中的对象具有3种状态:
1. Transient Objects临时对象
Objects instantiated using the new operator aren't immediately persistent. Their state is transient, which means they aren't

associated with any database table row, and so their state is lost as soon as they're dereferenced.
新生成的对象, Session没有引用指向它, 没有放入session缓存中,它在数据库里没有相对应的数据.
2. Persist Objects持久化对象
A persistent instance is any instance with a database identity. Persistent instances are associated with the persistence manager.

Persistent instances are always associated with a Session and are transactional
放入session缓存中,Session有引用指向该对象, 它在数据库里有相对应的数据, 与数据库里的数据同步.
3. Detached Objects游离对象
Instances lose their association with the persistence manager when you close() the Session. We refer to these objects as detached,

indicating that their state is no longer guaranteed to be synchronized with database state; they're no longer under the management

of Hibernate.
已经被持久化,但不再处于session缓存中,Session已没有引用指向该对象, 数据库里可能还有相对应的数据, 但已不能与数据库里的数据同步.
Hibernate的那些行为可以影响对象的状态呢?下图有一个说明(该图来自互联网):

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值