-->
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.  [ 5 posts ] 
Author Message
 Post subject: java.lang.outofmemmory bulk insert
PostPosted: Fri Dec 19, 2003 5:34 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 5:03 am
Posts: 34
I'm trying to add lots off records this way, max 10.000 at one time. Then a i do some other things and come here again with the same session. And do this again. Than i see my that my application get slower and finally stops with a java.lang.outofmemmory error.

I don't know 100% for sure. But i think it goed wrong here. I searched for some time and found only the remark that using the same session for so many records will cause this problem. So i wonder should i close the session after a while and get a new one or are there other solutions. Or maybe my code beneath contains an error.

Any help is appreciated.

try {

// start transaction
session.clear();
session.beginTransaction();

// iterate over alle the data items and save
for (int i = 0; i < dataList.size(); i++) {

session.save((MsconsDataBO) dataList.get(i));

}

// flush and commit
session.flush();
session.connection().commit();

} catch (Exception e) {

try {

// do rollback because of an error
session.connection().rollback();

} catch (Exception eSub) {

Import.errorExceptionExit("[couldn't perform rollback: mscons data]", e);

}

Import.errorExceptionExit("[couldn't add: mscons data]", e);

} finally {

log.debug("inserted " + dataList.size() + " records");

}[/u]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2003 1:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The session should be have a quite short live time.
Try to create a new one sometimes (sometimes is related to your app, so can't be more specific)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2003 1:43 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
IMHO, session.clear() should clear everything. To me it looks like either a bug in Hibernate (unlikely) or just an application problem - these thousands of objects can not be garbage collected because there are still referencies to them (likely)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2003 2:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
NOt quite. Hibernate keeps some objects around until the afterTransactionCompletion() phase. So you need to actually close() the session (or just commit the txn), not just clear() it to release *all* associated memory.


Top
 Profile  
 
 Post subject: Re: java.lang.outofmemmory bulk insert
PostPosted: Sun Jan 11, 2015 4:40 pm 
Newbie

Joined: Sun Jan 11, 2015 4:28 pm
Posts: 5
gavin is right. I wrote about this and other possible problems with batching inserts with Hibernate.
You can check these articles and I hope they help you out:

http://korhner.github.io/hibernate/hibernate-performance-traps-part-1/
http://korhner.github.io/hibernate/hibernate-performance-traps-part-2/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.