title: Get stream from java.sql.Blob in Hibernate
body: <p>I'm trying to use hibernate @Entity with java.sql.Blob to store some binary data. Storing doesn't throw any exceptions (however, I'm not sure if it really stores the bytes), but reading does. Here is my test:</p>
  
  <pre><code>@Test
  public void shouldStoreBlob() {
      InputStream readFile = getClass().getResourceAsStream("myfile");
  
      Blob blob = dao.createBlob(readFile, readFile.available());
      Ent ent = new Ent();
      ent.setBlob(blob);
  
      em.persist(ent);
      long id = ent.getId();
  
      Ent fromDb = em.find(Ent.class, id);
  
      //Exception is thrown from getBinaryStream()
      byte[] fromDbBytes = IOUtils.toByteArray(fromDb.getBlob().getBinaryStream());
  }
  </code></pre>
  
  <p>So it throws an exception:</p>
  
  <pre><code>java.sql.SQLException: could not reset reader
      at org.hibernate.engine.jdbc.BlobProxy.getStream(BlobProxy.java:86)
      at org.hibernate.engine.jdbc.BlobProxy.invoke(BlobProxy.java:108)
      at $Proxy81.getBinaryStream(Unknown Source)
      ...
  </code></pre>
  
  <p>Why? Shouldn't it read bytes form DB here? And what can I do for it to work?</p>