I have a Quartz scheduled Job that is run every minute.
The Job uses hibernate.
For some reason it seems that when using HQL queries, some objects never get cleaned by the garbage collector (checked with profiler).
The method called every minute using HQL:
public List getItems() {
Session session = null;
try {
session = sessionFactory.openSession();
List items = session.find("FROM item IN CLASS Item WHERE item.process=1 ORDER BY item.id");
return items;
} catch (HibernateException e) {
throw new RuntimeException(e.getMessage(), e);
} finally {
try {
if (session!=null) session.close();
} catch (HibernateException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
The method converted to use the Criteria API
public List getItems() {
Session session = null;
try {
session = sessionFactory.openSession();
Criteria c = session.createCriteria(Item.class);
c = c.add(Expression.eq("process", new Integer(1)));
c = c.addOrder(Order.asc("id"));
List l = c.list();
return l;
} catch (HibernateException e) {
throw new RuntimeException(e.getMessage(), e);
} finally {
try {
if (session!=null) session.close();
} catch (HibernateException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
Using the Criteria API no objects are left hanging behind, but using the HQL version, the following classes are never garbage collected
a) net.sf.hibernate.type.ManyToOneType
b) net.sf.hibernate.hql.QueryTranslator
c) net.sf.hibernate.sql.QueryJoinFragment
For each run (ie. every minute), there are created 2 objects of type a) and one of type b) and c) each.
Any ideas what's happening?
Using hibernate 2.1.4 with mysql.
|