title: Storing byte array image using JPA2 in PostgreSQL
body: <p>I am trying to store an image in the database but when I read the value I am getting always null.</p>
  
  <p>I've tried several combinations of following annotations but result is always same:</p>
  
  <pre><code>@Lob
  @Basic(fetch = FetchType.EAGER)
  @Type(type="org.hibernate.type.BinaryType")
  private byte[] image;
  </code></pre>
  
  <p>persistence.xml:</p>
  
  <pre><code>&lt;persistence-unit name="primary" transaction-type="JTA"&gt;
      &lt;jta-data-source&gt;java:jboss/datasources/WheelGoDS&lt;/jta-data-source&gt;
      &lt;properties&gt;
          &lt;property name="hibernate.hbm2ddl.auto" value="create" /&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
          &lt;property name="hibernate.current_session_context_class" value="jta"/&gt;
          &lt;property name="hibernate.show_sql" value="true" /&gt;
          &lt;property name="hibernate.archive.autodetection" value="class" /&gt;
          &lt;property name="hibernate.connection.useUnicode" value="true" /&gt;
          &lt;property name="hibernate.connection.characterEncoding" value="UTF-8" /&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>When I use only <code>@Lob</code> I've noticed that using pgAdmin i see numeric value. Otherwise I see <code>binary data</code>. My questions are:</p>
  
  <ol>
  <li>Is there reliable way to store and read binary data using JPA2?</li>
  <li>Is there way to read binary data in postgres? Because right now I am not sure if they are even correctly stored.</li>
  </ol>