sessionfactory.openSession()和sessionfactory.openStatelessSession()之间的区别? [英] difference between sessionfactory.openSession() and sessionfactory.openStatelessSession()?

查看:683
本文介绍了sessionfactory.openSession()和sessionfactory.openStatelessSession()之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道上面提到的休眠类sessionfactory类的两个方法之间的概念上的区别,如果用简单的例子来说明的话。 前者打开一个正常的(有状态的)会话,而后者打开一个无状态的会话。



根据 Javadoc ,无状态会话是:


用于对数据库执行批量操作的面向命令的API。

无状态会话没有实现一级缓存,也没有与任何二级缓存交互,也没有实现事务性的后写或自动脏检查,也没有将操作级联到关联的实例。集合被无状态会话忽略。通过无状态会话执行的操作绕过了Hibernate的事件模型和拦截器。由于缺乏第一级缓存,无状态会话容易受到数据混叠效应的影响。对于某些类型的事务,无状态会话的执行速度可能比有状态会话。



I want to know the conceptual difference between the above mentioned two methods of the hibernates sessionfactory class if poosible with simple example.

解决方案

The former opens a normal (stateful) session, while the latter (probably not surprisingly) a stateless session.

According to the Javadoc, a stateless session is:

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.

这篇关于sessionfactory.openSession()和sessionfactory.openStatelessSession()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆