我使用Hibernate 4.0将jpeg存储到postgres 9.1.4(jdbc是postgresql-9.1-901.jdbc4.jar)的bytea列(byte[]是Hibernate实体,没有额外的类型定义)。
hibernate存储过程工作得很好,因为我可以使用数据库工具转储bytea列并仍然获取jpeg。基本上是:
在managedBean中

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

此时,字节看起来像[-1,-40,-1,-32,0,16,74,70,…]
但是,问题从我通过hibernate检索开始。数据似乎以某种方式被修改或损坏。
byte [] bytes;
bytes = entity.getImage();

此时,字节变为[-26、100、56、102、102、101、48、48,…]
冬眠获得者是
@Column(name = "image")
public byte[] getImage() {
    return image;
}

感谢您的帮助,谢谢!

最佳答案

postgresql.conf中的change bytea_output=“escape”
或者运行这个
将tea_output设置的数据库dbname改为“escape”;

关于image - Hibernate Postgres Bytea检索问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17667480/

10-16 03:51