Can somebody help me understand this?
I looked at the code taken from
http://caveatemptor.hibernate.org
Initially I did not include the property in cfg.xml file, as I thought , if none provided, thread is taken by default.
<property name="hibernate.current_session_context_class">thread</property>
However, when I tried to do something like
Session session = HibernateUtil.getSessionFactory().openSession();
Session sessionNew = HibernateUtil.getSessionFactory().getCurrentSession();
got an exception
Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured!
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:540)
at hello.HelloWorld.main(HelloWorld.java:15)
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
I tried
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
Please clarify.