aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hiberante - differnce between methods from SessionFactory  - openSession() and getCurrentSession() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hiberante - differnce between methods from SessionFactory  - openSession() and getCurrentSession() " Watch "Hiberante - differnce between methods from SessionFactory  - openSession() and getCurrentSession() " New topic
Author

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

Witold Marshal
Ranch Hand

Joined: Feb 05, 2012
Posts: 48
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

Joined: Jul 19, 2011
Posts: 175

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.


Please correct my English.
Witold Marshal
Ranch Hand

Joined: Feb 05, 2012
Posts: 48
Thanks, it seems reasonable.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hiberante - differnce between methods from SessionFactory - openSession() and getCurrentSession()