Hibernate Postgres Bytea检索问题 [英] Hibernate postgres bytea retrieval issue
问题描述
我正在使用Hibernate 4.0将jpegs存储到postgres 9.1.4(jdbc是postgresql-9.1-901.jdbc4.jar)中,通过teatea列(byte []是休眠实体,没有额外的类型def)。
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).
休眠存储过程工作正常,因为我可以使用数据库工具来转储bytea列并仍然获取jpeg。基本上是:
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:
在managedBean中
In the managedBean
byte [] bytes;
bytes = IOUtils.toByteArray(file.getInputstream());
entity.setImage(bytes);
此时,字节看起来像[-1,-40,-1,-32, 0,16,74,70,...]
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();
此时,字节变为[-26,100,56,102,102,101, 48,48,...]
At this point, the bytes become [-26, 100, 56, 102, 102, 101, 48, 48,...]
休眠获取器是
@Column(name = "image")
public byte[] getImage() {
return image;
}
感谢任何人都可以提供帮助,谢谢!
Appreciate if anyone can assist, thanks!
推荐答案
在postgresql.conf中更改bytea_output ='escape'
change bytea_output='escape' in postgresql.conf
或运行
ALTER DATABASE dbname SET bytea_output为'escape';
ALTER DATABASE dbname SET bytea_output TO 'escape';
这篇关于Hibernate Postgres Bytea检索问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!