• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Safety when we do sessionFactory.getCurrentSession

 
Stanley Walker
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
This is a question one of my juniors asked me and I was completely dumbstruck.

according to java docs for Hibernate :

for Session
It is not intended that implementors be threadsafe. Instead each thread/transaction should obtain its own instance from a SessionFactory.


for SEssionFactory.getCurrentSEssion()
Obtains the current session. The definition of what exactly "current" means controlled by the CurrentSessionContext impl configured for use.


So if session object is not threadsafe, what happens when two threads call sessionFactory.getCurrentSession() .... if they get the same session object will there not be chances of all the dangers that threads cause when they get the same instance?

java api of CurrentSessionContext did not help and when i browsed through the code for implementors of CurrentSessionContext, it seemed to me that it is returning the same session object.

Please help, this has been bugging me for some time now.
 
Stanley Walker
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really looking forward to any help with the above question
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic