title: Java Large file to be saved in database - Object design
body: <p>I am trying to figure out object design to implement large file(~600 MB) respository in the Database using hibernate.
  Please suggest a correct approach/design?</p>
  
  <pre><code>class ModelClass{
  
  String name;  //meta data
  ...
  
  Option 1. 
      byte[] file; // dont want to load the content of the entire file 
                             // in memory by using this but hibernate recognizes 
                             // this datatype
  Option 2.
      InputStream inputStream;
      OutputStream outputStream;
      // I can have the methods to provide the input or output stream 
                // but i dont think its a clean approach. I am not sure how 
                // I will be able to work with hibernate with streams
  Option 3.
      File fileHandle; 
  }
  </code></pre>
  
  <p>Any other options??</p>
  
  <p>I would like to call save(Object) method of hibernateTemplate to save the object in Database. Dont know if I should have just the meta-data in the class and handle the file save and retreive seperately. </p>
  
  <p>Thanks in advance.</p>
  
  <p>Another workable solution is to use "Work" Interface. The purpose was to avoid loading the file content into memory.</p>
  
  <pre><code>session.doWork(new Work(){
      @Override
      public void execute(Connection conn) {
          //direct sql queries go here 
      }
  
  });
  </code></pre>