关于hibernate session中的三个状态
2007-12-13 03:26
435 查看
org.hibernate
Interface Session
All Superinterfaces: Serializable All Known Subinterfaces: EventSource, Session All Known Implementing Classes: SessionImpl public interface Session extends SerializableThe main runtime interface between a Java application and Hibernate. This is the central API class abstracting the notion of a persistence service.
The lifecycle of a Session is bounded by the beginning and end of a logical transaction. (Long transactions might span several database transactions.)
The main function of the Session is to offer create, read and delete operations for instances of mapped entity classes. Instances may exist in one of three states:
transient: never persistent, not associated with any Session
persistent: associated with a unique Session
detached: previously persistent, not associated with any Session
Transient instances may be made persistent by calling save(), persist() or saveOrUpdate(). Persistent instances may be made transient by calling delete(). Any instance returned by a get() or load() method is persistent. Detached instances may be made persistent by calling update(), saveOrUpdate(), lock() or replicate(). The state of a transient or detached instance may also be made persistent as a new persistent instance by calling merge().
save() and persist() result in an SQL INSERT, delete() in an SQL DELETE and update() or merge() in an SQL UPDATE. Changes to persistent instances are detected at flush time and also result in an SQL UPDATE. saveOrUpdate() and replicate() result in either an INSERT or an UPDATE.
It is not intended that implementors be threadsafe. Instead each thread/transaction should obtain its own instance from a SessionFactory.
A Session instance is serializable if its persistent classes are serializable.
通过以上的描述,我们可以得出如下三种状态关系图
Transient 瞬时态
Persistent 持久态
Detached 游离态
相关文章推荐
- Hibernate初学者---关于Session和它的三种状态
- Hibernate 笔记3 关于SessionFactory,Session 以及 三大状态(Transient、Persistent、Detached)
- Hibernate的学习之路十(持久化对象的三个状态)
- Hibernate中Session的缓存及对象的状态
- hibernate的对象状态和opensessioninviewfilter的作用
- 关于hibernate中对象的三种状态分析
- hibernate中PO对象的三种状态分析以及session中的一些方法的区别
- 关于Hibernate Could not obtain transaction-synchronized Session for current thread
- 关于JSP中request,response,session三个内置对象的常用方法
- [原创]java WEB学习笔记79:Hibernate学习之路--- 四种对象的状态,session核心方法:save()方法,persist()方法,get() 和 load() 方法,update()方法,saveOrUpdate() 方法,merge() 方法,delete() 方法,evict(),hibernate 调用存储过程,hibernate 与 触发器协同工作
- Hibernate入门BLOG [三、session的常用方法和hibernate对象的3种状态]
- hibernate 一级缓存(Session缓存)和持久化对象的四种状态
- 【java】——Hibernate持久化对象的三个状态
- hibernate简介(Session,几种状态,方法······等)概括全面,经典
- 关于GridView翻页checkBox状态保存的问题 (session)
- hibernate中session的三种状态
- 推荐三个关于Azure的Session(pdc2008大会)
- [转]Hibernate Session各种状态转换方法分析
- 关于hibernate中对象的三种状态分析
- 关于SSH整合中对于Hibernate的Session关闭的问题