Hibernate postgres bytea retrieval issue

帅比萌擦擦* 提交于 2019-12-13 12:15:53

问题


I am using Hibernate 4.0 to store jpegs into postgres 9.1.4 (jdbc is postgresql-9.1-901.jdbc4.jar) bytea column(byte[] is the hibernate entity, without extra type def).

The hibernate storing process works fine because I can use Database tools to dump the bytea column and still get the jpegs. It is basically:

In the managedBean

byte [] bytes;
bytes = IOUtils.toByteArray(file.getInputstream());
entity.setImage(bytes);

At this point, the bytes look like [-1, -40, -1, -32, 0, 16, 74, 70, ...]

However, the problem starts with I am retrieving via hibernate. The data seems modified or corrupted somehow.

byte [] bytes;
bytes = entity.getImage();

At this point, the bytes become [-26, 100, 56, 102, 102, 101, 48, 48,...]

The hibernate getter is

@Column(name = "image")
public byte[] getImage() {
    return image;
}

Appreciate if anyone can assist, thanks!


回答1:


change bytea_output='escape' in postgresql.conf

or run this

ALTER DATABASE dbname SET bytea_output TO 'escape';



来源:https://stackoverflow.com/questions/17667480/hibernate-postgres-bytea-retrieval-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!