-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Excess Memory Consumption with Hibernate
PostPosted: Wed Jan 24, 2007 6:46 pm 
Newbie

Joined: Tue Jan 23, 2007 9:02 pm
Posts: 3
I wrote this simple program:

Code:
public static void main(String[] args) throws Exception {
Session s = HibernateUtil.getSession();
ScrollableResults scr = s.createCriteria(Match.class).setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY);
s.close();
}

This program fails to run with OutOfMemoryException. After setting jvm parameter to -Xmx128m, I was able to run the program. Execution of second line of code increases the program memory from 18M to 110M. I havent even begun scrolling the ResultSet and the memory consumption has gone up drastically.

The table backing the class is not too big ~ 5000 rows. Some might argue that I am fetching too much data into memory, but I am using the ScrollableResults interface and it should fetch data like a JDBC ResultSet.
I examined the first level session cache via SessionStatistics object after line 2, it had 0 entites and collection. Where is all the memory being consumed? I havent enabled second-level cache.

This is with MySQL database version 5.0.27 with 5.0.4 JDBC conncetor from MySQL and Hibernate 3.2

Thanks
Avneesh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 7:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so did you try doing it with pure jdbc ?

...and how many other classes do you have mapped?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 7:46 pm 
Newbie

Joined: Tue Jan 23, 2007 9:02 pm
Posts: 3
max wrote:
so did you try doing it with pure jdbc ?

...and how many other classes do you have mapped?


OK the jdbc driver sucks!! Pure JDBC has the same memory consumption. I just had one class mapped to one table.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 7:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Yes the JDBC driver is not implemented well. This is common when dealing with scrollable for many JDBC drivers. The problem is the many drivers collected the whole result (in your case 5000 tuples of data) into memory then allows this in memory pool to be walked rather than using the native db cursors.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.