Hibernate version: 3.0.5
Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="hibernate">
<class name="ParentClass">
<id name="id" type="long">
<generator class="native"/>
</id>
<discriminator column="discriminator"/>
<version name="version"/>
<subclass name="ChildClass"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():SessionFactory factory = new Configuration().configure("/jdbc.cfg.xml").buildSessionFactory();
Session session = factory.openSession();
ParentClass parent = (ParentClass) session.load(ParentClass.class, 1L);
Hibernate.initialize(parent);
ChildClass child = (ChildClass) session.get(ChildClass.class, 1L);
parent = null;
child = null;
session.clear();
session.close();
factory.close();
while (true)
{
Thread.sleep(1000);
System.gc();
}
Name and version of the database you are using:MySQL 4.1.14-nt
Class definitionsCode:
package hibernate;
import java.io.Serializable;
public class ParentClass implements Serializable
{
private Serializable id;
private Serializable version;
public Serializable getId()
{
return id;
}
public void setId(Serializable id)
{
this.id = id;
}
public Serializable getVersion()
{
return version;
}
public void setVersion(Serializable version)
{
this.version = version;
}
}
package hibernate;
public class ChildClass extends ParentClass
{}
Database rows
Ensure there is a single row in the database of type ChildClass, with id=1
-------
I am using JProfiler for memory profiling and I can see that when the code reaches the never-ending loop, there is an instance of ChildClass resident in memory with a reference from CGLIBLazyInitializer. My expectation is for all instances of ParentClass and ChildClass to be non-referenced after session.clear() is invoked.
My actual application uses Query.iterate() for bulk processing operations and it runs out of memory because Session.clear() is not releasing all references as expected.
I welcome your help.