Forums Register Login

java.lang.OutOfMemoryError: Java heap space in session.save()

+Pie Number of slices to send: Send
Hi,
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>(Buffer.java:59)
at com.mysql.jdbc.MysqlIO.sendSplitPackets(MysqlIO.java:3765)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3296)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1983)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2427)
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1980)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1451)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)

I tried commenting the hibernate session.save(objref); 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.
+Pie Number of slices to send: Send
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.
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2076 times.
Similar Threads
Hibernate 3.0 : Where am I going wrong?
Java heap space
File upload using Tomcat6.0 gives java.lang.OutOfMemoryError: Java heap space[/b]
MySQL, Hibernate, and allowNanAndInf Flag
Problem in using java to Store 1GB+ files in a MySQL database
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 08:01:56.