This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • 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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!