I am in the process of Upgrading Hibernate from version 2.1.6 to 3.0.5. Well as we are making use of Spring Framework, we are also upgrading Spring from version 1.0.1 to 1.2.4 (as it supports Hibernate 3). What I have observed is: After certain DB calls the application is not working and showing java.lang.OutOfMemoryError. When I observe the stack trace it shows that the Session objects are not being closed:
Code:
2005-10-19 10:40:16,689 DEBUG [com.abc.persistence.MyHibernateTemplate] Found thread-bound Session for HibernateTemplate
2005-10-19 10:40:19,513 DEBUG [com.abc.persistence.MyHibernateTemplate] Eagerly flushing Hibernate session
2005-10-19 10:40:19,513 DEBUG [com.abc.persistence.MyHibernateTemplate] Not closing pre-bound Hibernate Session after HibernateTemplate
The code for MyHibernateTemplate is as follows:
Code:
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateTemplate;
public class MyHibernateTemplate extends HibernateTemplate
{
/**
* @see org.springframework.orm.hibernate3.HibernateAccessor#flushIfNecessary(org.hibernate.Session, boolean)
*/
public void flushIfNecessary(Session session, boolean existingTransaction)
throws HibernateException
{
// Overriden to prevent flushing if Session.flushMode is NEVER
boolean assumeReadOnlyTransaction = existingTransaction && session.getFlushMode().equals(FlushMode.NEVER);
if( !assumeReadOnlyTransaction )
{
super.flushIfNecessary(session, existingTransaction);
}
}
}
Well, I am not very sure whether this problem is due to Spring or Hibernate. But it used to work in the earlier Spring & Hibernate. Plz. let me know what's going wrong.