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.  [ 3 posts ] 
Author Message
 Post subject: Batch Blob Insert OutOfMemory
PostPosted: Mon Apr 11, 2005 5:20 pm 
Newbie

Joined: Thu Apr 07, 2005 8:07 pm
Posts: 2
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.1.8 and 3.0 release

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Transaction tx = session.beginTransaction();
for(int i=0;i<256;i++)
{
BlobTest blobTest = new BlobTest();

// let's say that baos is a byte array of 500k of data, with a new array of 500k of data every loop iteration

// also the 256 that it iterates to, is actually variable in the real code

blobTest.setBlob(Hibernate.createBlob(baos.toByteArray()));
session.save(blobTest);
sesiion.evict(blobTest);
if(i%20==0)
{
// batch solution as per Gavin's blog
session.flush();
session.clear();
}
}
tx.commit();

Full stack trace of any exception that occurs:
java.lang.OutOfMemoryException

Name and version of the database you are using:
MSSQL 2k,using JTDS 1.0.2


It doesn't seem to flush out the instances of blobTest or possibly the reference to the Blob. I implemented this in an alternative way by just asking Hibernate for a connection, and feeding the DB the binary stream via PreparedStatement instead, and that does not have the memory leak.

Increasing the java heap can help this case but if the looping of the blobs exceeds/nears the heap limit it will also go Out of memory. This cannot be the solution since it can only work for one user at a time.

Is there a different workaround? Like RTFM (pointer to section please). Or the DIY approach via connection is the Acceptable Solution (tm)?

Thanks for suggestions, criticisms, comments, flames, whatever :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 11, 2005 6:30 pm 
Newbie

Joined: Thu Apr 07, 2005 8:07 pm
Posts: 2
Funny, after I posted this, I accidentallly stumbled upon a possible fix for my situation, by just setting

hibernate.cache.use_query_cache false

Now I just have to find a way use query cache for everything but the stupid blob section :) still open to solutions, while I search on my own.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 28, 2005 2:42 pm 
Regular
Regular

Joined: Wed Dec 17, 2003 1:58 pm
Posts: 102
Did you ever find a solution to this? I have a similar problems with a clob...


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