title: Read/write blob data in chunks with Hibernate
body: <p>Is there a way to read and write from a <code>blob</code> in chunks using <code>Hibernate</code>. 
  Right now I am getting <code>OutOfmemoryException</code> because the whole blob data is loaded in memory into a <code>byte[]</code>.</p>
  
  <p>To be more specific, let's say I want to save a large file into a database table called <code>File</code>.</p>
  
  <pre><code>public class File {
     private byte[] data;
  }
  </code></pre>
  
  <p>I open the file in a FileInputStream and then what? 
  How do I tell Hibernate that I need to stream the content and will not give the whole <code>byte[]</code> array at once?
  Should I use <code>Blob</code> instead of <code>byte[]</code>? Anyway how can I stream the content?</p>
  
  <p>Regarding reading, is there a way I can tell hibernate that (besides the lazy loading it does) I need the blob to be loaded in chunks, so when I retrieve my <code>File</code> it should not give me <code>OutOfMemoryException</code>.</p>
  
  <p>I am using:</p>
  
  <ul>
  <li>Oracle 11.2.0.3.0 </li>
  <li>Hibernate 4.2.3 Final</li>
  <li>Oracle Driver 11.2</li>
  </ul>