2013-07-16 102 views
2

我使用Hibernate 4.0将jpegs存储到postgres 9.1.4(jdbc是postgresql-9.1-901.jdbc4.jar)bytea列(byte []是hibernate实体,没有额外的类型def) 。Hibernate postgres bytea检索问题

hibernate存储过程正常工作,因为我可以使用数据库工具转储bytea列并仍然获取jpegs。它基本上是:

在managedBean

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

此时,该字节的样子[-1,-40,-1,-32,0,16,74,70,... ]

但是,问题始于我通过休眠来检索。数据似乎被修改或损坏了。

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

此时,字节成为[-26,100,56,102,102,101,48,48,...]

的休眠吸气剂是

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

欣赏有人能帮忙,谢谢!

+0

看看http://stackoverflow.com/questions/10671471/how-to-store-image-into-postgres-database-using-hibernate,特别是http://stackoverflow.com/questions/3677380/适当的hibernate注释字节 – DrColossos

+0

谢谢。看着那些之前,他们没有帮助。 – snlm95

回答

3

在postgresql.conf中变化bytea_output = '逃离'

或运行该

ALTER数据库数据库名称SET TO bytea_output '逃离';

+0

它很好用。感谢您的帮助。 – snlm95