I'm learning Hibernate and I have a very basic question on Hibernate Session concept. As you know, there are two methods openSession() and getCurrentSession() in SessionFactory and as far as I understand, when we use current_session_context_class = thread, then a session created is bound to the Thread under execution and the thread that created that session. So, if a session is created using openSession() and then call getCurrentSession(), it should return the same session instance.
I see the assertion failing at Assert.assertEquals(session1,session3);
Since the whole execution is under same single main thread, should not session1 and session3 be equal??
Also, I tried to call getCurrentSession() directly as the only call and I still see a Session being returned. Does getCurrentSession() creates a new session, if none existing bound to Thread.
Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured!
So, I added the property in file and again tried to create two sessions.
Since the sessions are Thread bound and I'm running in same Main thread, should not both session objects be same and equal
and I got false in both the cases.
Secondly, if there is no session already created by openSession() method and bound to a context like Thread, if we invode getCurrentSession(), does that create a new Session and bound to Thread.
Or openSession() should have been called prior to getCurrentSession() is called. From