Using openSession() over getCurrentSession() - when and why?
I know you would use openSession() so that you could self-manage the closing and flushing of the session, however, why would you want to do this manually?
One would use openSession()
to implement long conversations (i.e. when you want to use use a single Session for several database transactions aka the extended Session pattern).
I have used openSession() when I wanted to perform a transaction in isolation to the current session though I am not sure if this is a correct use of openSession().
Hmm... What? Transaction and Session are different concepts. What do you mean exactly?
Why would you want multiple sessions open?
That's not the intention.
References
- Hibernate Core Reference Documentation
- 11.1.2. Long conversations
- Hibernate Wiki
- Sessions and transactions