I am using the latest version of everything I can find and still have the same problem. Everytime tomcat reloads my hibernate test app it gobbles up memory and latter produces out of memory errors.
I am just using hibernate with its assoicated libary. I have a listner configured that starts the sesssionFactory (see below). And I reload using the tomcat manager.
It seems that tomcat out of the box with hibernate out of the box doesn't work together, is that right?
I see this thread here
http://forum.hibernate.org/viewtopic.ph ... cat+memory
but it doesn't offer any solutions but to go to latest releases of libaries which I think I have done.
What am I doing wrong?
Hibernate version:
3.1.2
Mapping documents:
Lots (I will post but I don't think this is the issue)
Code between sessionFactory.openSession() and session.close():
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {
//private static Log log = LogFactory.getLog(HibernateUtil.class);
private static final SessionFactory sessionFactory;
private static final Configuration conFig;
static {
try {
// Create the SessionFactory
conFig = new Configuration().configure();
sessionFactory = conFig.buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
//log.error("Initial SessionFactory creation failed.", ex);
ex.printStackTrace();
throw new ExceptionInInitializerError(ex);
}
}
public static ThreadLocal session = new ThreadLocal();
public static Session currentSession() {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession() {
Session s = (Session) session.get();
if (s != null)
s.close();
session.set(null);
//sessionFactory.close();
}
public static String getUrl(){
return conFig.getProperty("hibernate.connection.url");
}
public static String getUsername(){
return conFig.getProperty("hibernate.connection.username");
}
public static String getPassword(){
return conFig.getProperty("hibernate.connection.password");
}
public static void setUrl(String in){
conFig.setProperty("hibernate.connection.url", in);
}
}
import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;
public class HibernateListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
System.out.println("********************** Starting Context Here!!! ********************** ");
HibernateUtil.currentSession(); // Just call the static initializer of that class
}
public void contextDestroyed(ServletContextEvent event) {
System.out.println("********************** Stoping Context Here!!! ********************** ");
HibernateUtil.currentSession().close(); // Free all resources
//((PersistenceManager) event.getServletContext().getAttribute("persistenceManager")).close();
}
}
Name and version of the database you are using:
Oracle 9i