Hello guys,
I'm using Hibernate but I'm having a warning...
This warning is about don't close the session?
Code:
net.sf.hibernate.impl.SessionImpl afterTransactionCompletion() was never called
I'm using Struts. I always open a Transaction, do commit/rollback and close the Hibernate Session in the finally method... I use ThreadLocal pattern too.
please, can somebody help me? My code is correct?
HibernateThreadLocalSession is a class wich implement ThreadLocal pattern.
thank you very much
Code:
HttpSession session = request.getSession();
Transaction t = null;
try
{
try
{
t = HibernateThreadLocalSession.currentSession().beginTransaction();
}
catch (RuntimeException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
// abstract method, all subclasses implement it, I use DAO pattern and TreadLocal
ActionForward forward = performDBTask(mapping, form, request, response);
if (request.getAttribute("org.apache.struts.action.ERROR") == null)
{
t.commit();
}
else
{
t.rollback();
}
return forward;
}
catch (Exception exPA)
{
exPA.printStackTrace();
try
{
if (t != null)
{
t.rollback();
}
}
catch (HibernateException e1)
{
System.out.println("Error rollback: " + e1.getClass() + " - " + e1.getMessage());
}
finally
{
// close session in threadlocal
HibernateThreadLocalSession.closeSession();
}