Currently, in the a DB I have the following table (PostgreSQL 9.2
):
jackpot_image
id jackpot_id mime_type image_data
serial integer varchar(32) bytea
I have the following entity:
@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
}
and thw following DAO:
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);
}
}
The thing is when I'm trying to save and then retrieve the image I get the different arrays of byte.
JackpotImage image;
JackpotImageDao imageDao;
//Getting image and ImageDAO
imageDao.save(image);
JackpotImage img = imageDao.selectImage(image.getId());
Now, the image
's binary data differs from img
's binary data. Why? And how can I fix that?