In scenario @1:
Code:
Session sess1 = HibernateUtils.getCurrentSession();
sess1.close();
Session sess2 = HibernateUtils.getCurrentSession();
Because your using a ThreadLocal and sess1 and sess2 referr to teh same session instance. Thus, closing sess1 is the same as closing sess2.
In scenario #2:
Code:
Session sess1 = HibernateUtils.getCurrentSession();
HibernateUtils.closeSession();
Session sess2 = HibernateUtils.getCurrentSession();
If you look at what you code is doing in your HibernateUtils class, the answer should be very clear :) Your HibernateUtils.closeSession() nulls out the ThreadLocal value and your HibernateUtils.getCurrentSession() returns a new Session when the ThreadLocal value is null.
This is why it's generally not a good idea to manually close a session when using CMT :)
Ryan-