I just updated that code with catch blocks for plain old Exception. My logs don't show anything out of the ordinary. I also just noticed that this warning always appears first in the logs ...
12-01-04 10:08:29 [main] WARN net.sf.hibernate.impl.SessionFactoryObjectFactory: InitialContext did not implement EventContext
But after searching in the forums I see that this warning is probably benign.
I also put more debugging in the code that opens and closes the session:
Code:
protected static Session getHibernateSession()
throws NamingException, HibernateException
{
Session s = (Session) session.get();
if (s == null)
{
if(_baseLog.isDebugEnabled())
{
_baseLog.debug("Acquiring new session factory");
}
SessionFactory sf = (SessionFactory) new
InitialContext().lookup("prospecting/hibernate/SessionFactory");
s = sf.openSession();
session.set(s);
}
else
{
if(_baseLog.isDebugEnabled())
{
_baseLog.debug("Session acquired from threadLocal");
}
}
return s;
}
and
Code:
protected static void closeHibernateSession()
throws HibernateException
{
if(_baseLog.isDebugEnabled())
{
_baseLog.debug("Closing session");
}
Session s = (Session) session.get();
session.set(null);
if (s != null)
{
s.close();
}
else
{
if(_baseLog.isDebugEnabled())
{
_baseLog.debug("S was null, not calling close()");
}
}
}
And what I see is that the session is opened and closed, yet I still get the warnings?
12-01-04 10:54:50 [http8080-Processor25] DEBUG com.MyClass: Acquiring new session factory
12-01-04 10:54:51 [http8080-Processor25] DEBUG com.MyClass: Closing session
12-01-04 10:54:51 [http8080-Processor25] DEBUG com.MyClass: Acquiring new session factory
12-01-04 10:54:51 [http8080-Processor25] DEBUG com.MyClass: Closing session
12-01-04 10:54:51 [http8080-Processor25] DEBUG com.MyClass: Acquiring new session factory
12-01-04 10:54:51 [http8080-Processor25] DEBUG com.MyClass: Closing session
12-01-04 10:54:51 [Finalizer] WARN net.sf.hibernate.impl.SessionImpl: afterTransactionCompletion() was never called
12-01-04 10:54:51 [Finalizer] WARN net.sf.hibernate.impl.SessionImpl: afterTransactionCompletion() was never called
12-01-04 10:54:51 [Finalizer] WARN net.sf.hibernate.impl.SessionImpl: afterTransactionCompletion() was never called
Should I be calling afterTransactionCompletion() myself?
Funny thing is, after serveral test runs I see that there is not always a one-to-one relationship between opening and closing the session to the warning. Sometimes the session is closed and opened several times with no warnings at all. Maybe the two aren't related?