Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.OutOfMemoryError: Java heap space in  RSS feed

Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have developed a web application that runs on Tomcat6 (run from console \bin and not as windows service) and uses hibernate 3 for OR mapping and MYSQL as database. my requirement is I have to upload files of size upto maximum 100MB and persist them in a table column in the database using hibernate.

I read the FileInputStream directly into Hibernate Blob object using Hibernate.createBlob(FileInputStream obj) method. In hibernate Pojo class and hbm.xml file the corressponding column name type is declared as blob. when I execute this application I am able to upload files of size upto 25MB successfully. but when i try to upload file of size greater than 25MB it is throwing OutOfMemoryError: Java heap space

java.lang.OutOfMemoryError: Java heap space
at com.mysql.jdbc.Buffer.<init>(
at com.mysql.jdbc.MysqlIO.sendSplitPackets(
at com.mysql.jdbc.MysqlIO.send(
at com.mysql.jdbc.MysqlIO.sendCommand(
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(
at com.mysql.jdbc.ConnectionImpl.execSQL(
at com.mysql.jdbc.PreparedStatement.executeInternal(
at com.mysql.jdbc.PreparedStatement.executeUpdate(
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(
at com.mysql.jdbc.PreparedStatement.executeBatch(
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(
at org.hibernate.jdbc.AbstractBatcher.executeBatch(
at org.hibernate.engine.ActionQueue.executeActions(
at org.hibernate.engine.ActionQueue.executeActions(
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(
at org.hibernate.impl.SessionImpl.flush(
at org.hibernate.impl.SessionImpl.managedFlush(
at org.hibernate.transaction.JDBCTransaction.commit(

I tried commenting the hibernate; call and I am not getting the OutOfMemoryError.

Note: I am not supposed to use byte array to read the inputstream data into and then store it in database using hibernate since memory is a constraint for me. In mysql the max_allowed_packet size is 1024MB. kindly help.
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the thread upload-file-mysql-database-struts I already explained why i am against saving binary data, especially large ones in the database.
Save the path to the file in the database and save it to the filesystem.
Yes, my master! Here is the tiny ad you asked for:
Why should you try IntelliJ IDEA ?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!