Hi,
I'm trying to use Hibernate to store Blob (87MB) in MySQL and I get an Out Of Memory error. It works fine if if write custom JDBC code. It seems that Hibernate loads all binary data into memory instead of saving using a small buffer to save data. Is it a known problem or do I make a mistake in my hibernate config (see below).
Hibernate version: 3.0.5
<property name="hibernate.jdbc.batch_size">0</property>
<property name="hibernate.jdbc.use_streams_for_binary">true</property>
<property name="hibernate.cache.use_query_cache">false</property>
Mapping documents:
<hibernate-mapping>
<class name="sample.Record" table="UPLOADS">
<id name="id" column="UPLOADID" type="long" unsaved-value="0">
<generator class="increment" />
</id>
<property name="filename" type="string" column="FILENAME"/>
<property name="filedata" type="blob" column="BINARYFILE"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Transaction tx = session.beginTransaction();
Record record = new Record();
record.setFilename(file.getFileName());
record.setFiledata(Hibernate.createBlob(file.getInpuStream()));
session.save(record);
tx.commit();
Full stack trace of any exception that occurs:
OutOfMemory
Name and version of the database you are using:
MySQL 4.0.18 with set-variable = max_allowed_packet=100M
And ConnectorJ 3.1 JDBC Driver.
The generated SQL (show_sql=true):
Hibernate: insert into UPLOADS (FILENAME, BINARYFILE, UPLOADID) values (?, ?, ?)
|