Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0.2
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="com.redsoft.samples.hibernate3">
<class name="TemplateNode" table="tblissue302TemplateNode" >
<cache usage="read-write"/>
<id name="nodeId">
<generator class="native"/>
</id>
<property name="text"/>
<property name="text1" />
<property name="text2"/>
<property name="text3"/>
<property name="text4" />
<property name="text5"/>
<property name="text6"/>
<property name="text7" />
<property name="text8"/>
<property name="text9"/>
<property name="text10" />
<property name="text11"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
this.factory=factory;
s=factory.openSession();
System.out.println("*********************** Comparision Result***********************");
// Now we measure Hibernate's read performance
long begin;
long end;
try {
begin = System.currentTimeMillis();
Query q = s.createQuery("from " + TemplateNode.class.getName())
.setCacheable(false).setCacheMode(CacheMode.IGNORE);
List results = q.list();
Iterator iter = results.iterator();
while (iter.hasNext()) {
TemplateNode tn = (TemplateNode) iter.next();
tn.getText();
}
end = System.currentTimeMillis();
System.out.println("Hibernate spends: " + (end - begin) + "ms to read " + MAX_RECORDS + " records!" );
s.clear();
s.close();
factory.evict(TemplateNode.class);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("*****************************************************************");
Full stack trace of any exception that occurs:
[java] java.lang.OutOfMemoryError
[java] Exception in thread "main"
[java] Java Result: 1
BUILD SUCCESSFUL
Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):
[java] Hibernate: select templateno0_.nodeId as nodeId, templateno0_.text as text0_, templateno0_.text1 as text3_0
, templateno0_.text2 as text4_0_, templateno0_.text3 as text5_0_, templateno0_.text4 as text6_0_, templateno0_.text5 as
text7_0_, templateno0_.text6 as text8_0_, templateno0_.text7 as text9_0_, templateno0_.text8 as text10_0_, templateno0_
text9 as text11_0_, templateno0_.text10 as text12_0_, templateno0_.text11 as text13_0_ from tblissue302TemplateNode tem
lateno0_
[java] Hibernate spends: 3865ms to read 30000 records!
] *****************************************************************
Debug level Hibernate log excerpt:
Because we want to test the performance with hibernate3.0.2,
we repeatly open a new session and load all records in the table( records num in the table is 30000, although it is a large number, but it didn't yet overflow the jvm memory),
the testMain as follows:
<code>
public static void main(String[] args) throws Exception {
List mappingClasses=new ArrayList();
mappingClasses.add(TemplateNode.class);
SessionFactory sf=HibernateUtil.initHibernateSessionFactory("create",null,mappingClasses);
//firstly we insert 30000 records into the table
new InsertComparsionHibernate(sf);
/*then we repeatly open a new session by the same sessionFactory to read all the 30000 records */
for(int i=0;i<30;i++){
new ReadComparsionHibernate(sf);
}
sf.close(); //finally , close the sf
}
</code>
Question:
Although, we clear and close session,and ignore the cache when query listing, ;but this didn't avoid the Outofmemory error/
why? any wrong in our test code?
thanks!!