Hibernate学习笔记:对象生命周期
2009-08-31 17:17
375 查看
学到这里我想谈一下自己的感受:在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的那些行为可以影响对象的状态呢?下图有一个说明(该图来自互联网):
对象以及对象之间的关系.当配置文件编写完毕之后,对象和对象之间的关系也就确定了.由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的那些行为可以影响对象的状态呢?下图有一个说明(该图来自互联网):
相关文章推荐
- [原创]java WEB学习笔记94:Hibernate学习之路---session 的管理,Session 对象的生命周期与本地线程绑定
- Hibernate视频学习笔记(2)持久对象的生命周期及Query接口初步
- hibernate学习笔记之(持久对象的生命周期及Query接口初步)
- Hibernate学习笔记---1.java对象持久化技术
- Hibernate学习笔记 merge()方法--add对象
- Hibernate学习笔记2--持久化对象的状态
- hibernate学习笔记04----检索对象的方式
- Servlet学习笔记(1)--第一个servlet&&三种状态对象(cookie,session,application)&&Servlet的生命周期
- Hibernate学习(4)- Hibernate对象的生命周期
- Hibernate学习笔记 -- day10 OID、对象导航查询、原生SQL
- [原创]java WEB学习笔记47:Servlet 监听器简介, ServletContext(Application 对象), HttpSession (Session 对象), HttpServletRequest (request 对象) 监听器,利用listener理解 三个对象的生命周期
- Hibernate学习笔记:session操作对象
- hibernate学习(持久化对象生命周期)
- hibernate框架学习笔记4:主键生成策略、对象状态
- HIbernate学习笔记3 之 缓存和 对象的三种状态
- Hibernate 学习笔记-1-2(测试Hibernate中session的生命周期以及CRUD)
- Hibernate学习笔记(四)----核心开发接口、对象的三种状态、session常用方法
- hibernate3.3.2学习笔记---三种对象状态&删除数据&获取数据库对象&更新数据库对象
- Hibernate学习笔记:session操作对象