title: Java JPA where to use byte[] or Blob
body: <p>I'm trying to store images as binaries into a Postgres database with Java JPA.<br>
  I tried to use <code>@Entity</code> class with <code>Blob</code> field, which works well, but many people use just 
  <code>byte[]</code> arrays. see <a href="https://stackoverflow.com/a/5032819/2877029">#1</a>, <a href="https://stackoverflow.com/a/35507816/2877029">#2</a>, etc. </p>
  
  <p><strong>What are the advantages and disadvantages of both?<br>
  When one should be preferred over another?</strong></p>
  
  <pre><code>@Entity
  public class ImageEntity {
      @Id
      private UUID id;
      @Lob
      @Fetch(FetchMode.JOIN)
      private Blob data;
  }
  
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>// create Blob:         
  byte[] myBytes = ...
  Blob blob = new SerialBlob(myBytes);
  </code></pre>