2013-07-16 48 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