Thread:
 Implementing destroy() for cleanup 
 damiel   07 Feb 2007, 03:34 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: damiel (07 Feb 2007, 03:34) Replies: 0, Views: 16169
Subject: Implementing destroy() for cleanup
One problem I noticed with the HibernateSessionConversationFilter was
that when redeploying my application, the network connection to the
database was not released. I fixed this by implementing destroy() like this:

public void destroy()
{
    try
    {
        if (sessionFactory != null)
        {
            Session session = sessionFactory.getCurrentSession();
            if (session.isOpen()) session.close();
            sessionFactory.close();
        }
    }
    catch (HibernateException e)
    {
        logger.error("Failed to close session in destroy()", e);
    }
}

I'm not sure if this code is perfect, but it works for me. The resources
are now properly released when I redeploy the application.
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]