Using openSession () over getCurrentSession () - when and why?

This question relates to another question I asked, but what are the reasons why you use openSession () over getCurrentSession ()? I know that you would use openSession () so that you can independently control the closing and cleaning of the session, but why do you need to do this manually?

I used openSession () when I wanted to execute a transaction in isolation to the current session, although I'm not sure if this is the correct use of openSession ().

Why do you want to open multiple sessions?

+6
java hibernate jpa
source share
1 answer

I know that you would use openSession () so that you can independently control the closing and cleaning of the session, but why do you want to do this manually?

You can use openSession() to implement long conversations (i.e. when you want to use a single session for multiple database transactions , as well as an extended session template).

I used openSession () when I wanted to execute a transaction in isolation to the current session, although I'm not sure if this is the correct use of openSession ().

Hmm ... what? Transaction and session are different concepts. What do you have in mind?

Why do you want to open multiple sessions?

This is not an intention.

References

+4
source share

All Articles