title: Saving byte[] with hibernate to postgreSQL
body: <p>Currently, in the a DB I have the following table (<code>PostgreSQL 9.2</code>):</p>
  
  <pre><code>                        jackpot_image
  
       id       jackpot_id         mime_type        image_data
     serial      integer          varchar(32)         bytea
  </code></pre>
  
  <p>I have the following entity:</p>
  
  <pre><code>@Entity
  @Table(name = "jackpot_image")
  public class JackpotImage {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      private int id;
  
      @Column(name="jackpot_id")
      private int jackpotId;
  
      @Column(name="mime_type")
      private String mimeType;
  
      @Column(name="image_data")
      private byte[] imageData;
  
      //GET, SET
  
  }
  </code></pre>
  
  <p>and thw following DAO:</p>
  
  <pre><code>public class JackpotImageDao {
  
      public JackpotImage selectImage(int imageId){
          String hql = "FROM JackpotImage WHERE id = :imageId";
          Query query = getSession().createQuery(hql);
          query.setInteger("imageId", imageId);
          return (JackpotImage) query.uniqueResult();
      }
  
      public void save(JackpotImage image){
          getSession().saveOrUpdate(image);
      }
  }
  </code></pre>
  
  <p>The thing is when I'm trying to save and then retrieve the image I get the different arrays of byte.</p>
  
  <pre><code>JackpotImage image;
  JackpotImageDao imageDao;
  //Getting image and ImageDAO
  imageDao.save(image);
  JackpotImage img = imageDao.selectImage(image.getId());
  </code></pre>
  
  <p>Now, the <code>image</code>'s binary data differs from <code>img</code>'s binary data. Why? And how can I fix that?</p>