title: Hibernate - Out of memory inserting big blob
body: <p>In POJO i have:</p>
  
  <pre><code>public void setBlob(InputStream in, Long l) {
          this.blob = Hibernate.getLobCreator(SessionFactoryHelper.sessionFactory.getCurrentSession()).createBlob(in, l);
  }
  </code></pre>
  
  <p>I made  hibernate.jdbc.use_streams_for_binary true in config, but does it really change something?</p>
  
  <p>when saving entity, on session.flush() i get:</p>
  
  <pre><code>   org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
  INFO: HHH000010: On release of batch it still contained JDBC statements
  Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
  Heap dump file created [46180174 bytes in 1.662 secs]
      at java.util.Arrays.copyOf(Arrays.java:2271)
      at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:113)
      at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
      at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:140)
      at org.hibernate.type.descriptor.java.DataHelper.extractBytes(DataHelper.java:171)
      at org.hibernate.type.descriptor.java.BlobTypeDescriptor.unwrap(BlobTypeDescriptor.java:121)
      at org.hibernate.type.descriptor.java.BlobTypeDescriptor.unwrap(BlobTypeDescriptor.java:45)
      at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$4$1.doBind(BlobTypeDescriptor.java:105)
      at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:92)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300)
      at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:57)
      at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2599)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2853)
      at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3291)
      at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
      at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
      at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:275)
      at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
      at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
      at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1127)
  </code></pre>
  
  <p>Hibernate 4.1.
  Why hibernate unwrapping stream to bytea? How can i make hibernate to use prepared statement setBinaryStream? Really need help on this.</p>