java sessionfactory.openSession() 和 sessionfactory.openStatelessSession() 的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5496995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
difference between sessionfactory.openSession() and sessionfactory.openStatelessSession()?
提问by GuruKulki
I want to know the conceptual difference between the above mentioned two methods of the hibernates sessionfactory class if poosible with simple example.
如果可以通过简单的示例,我想知道上面提到的 hibernates sessionfactory 类的两种方法之间的概念差异。
采纳答案by Péter T?r?k
The former opens a normal (stateful) session, while the latter (probably not surprisingly) a stateless session.
前者打开一个普通(有状态)会话,而后者(可能并不奇怪)打开一个无状态会话。
According to the Javadoc, a stateless session is:
根据Javadoc,无状态会话是:
A command-oriented API for performing bulk operations against a database.
A stateless session does not implement a first-level cache nor interact with any second-level cache, nor does it implement transactional write-behind or automatic dirty checking, nor do operations cascade to associated instances. Collections are ignored by a stateless session. Operations performed via a stateless session bypass Hibernate's event model and interceptors. Stateless sessions are vulnerable to data aliasing effects, due to the lack of a first-level cache.
For certain kinds of transactions, a stateless session may perform slightly faster than a stateful session.
面向命令的 API,用于对数据库执行批量操作。
无状态会话不实现一级缓存,也不与任何二级缓存交互,也不实现事务性后写或自动脏检查,也不执行级联到关联实例的操作。无状态会话会忽略集合。通过无状态会话执行的操作绕过 Hibernate 的事件模型和拦截器。由于缺乏一级缓存,无状态会话容易受到数据混叠效应的影响。
对于某些类型的事务,无状态会话的执行速度可能比有状态会话稍快。