• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hiberante - differnce between methods from SessionFactory - openSession() and getCurrentSession()

 
Witold Marshal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand the difference between those two mtehods in the way that it is described in documentation.

As I know both method create Session object.
I suspect from what I have read that:
"getCurrentSession()" is only allowed in container calls during JTA transaction (?) and "openSession()" is valid outside JTA transaction and container (in utility class) (?)
Is that true?
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
openSession() is actually creating a new session every time it is called.
getCurrentSession() returns a session associated with the current context, that may or may not be a jta transaction. It may be a new one or the one previously used in the same context.
At least thats how i understand the documentation.
 
Witold Marshal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, it seems reasonable.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic