Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between sessionfactory.openSession() and sessionfactory.openStatelessSession()?

Tags:

java

hibernate

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

like image 865
GuruKulki Avatar asked Mar 31 '11 08:03

GuruKulki


1 Answers

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.

like image 74
Péter Török Avatar answered Sep 29 '22 09:09

Péter Török