【问题标题】:Hibernate postgres bytea retrieval issueHibernate postgres bytea 检索问题
【发布时间】:2013-07-14 02:22:36
【问题描述】:

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

hibernate 存储过程运行良好,因为我可以使用数据库工具转储 bytea 列并仍然获取 jpeg。基本上是:

在 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,...]

hibernate getter 是

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

如果有人可以提供帮助,谢谢!

【问题讨论】:

标签: image hibernate postgresql bytea


【解决方案1】:

在 postgresql.conf 中更改 bytea_output='escape'

或者运行这个

ALTER DATABASE dbname SET bytea_output TO 'escape';

【讨论】:

    猜你喜欢
    • 2023-01-08
    • 2014-09-02
    • 2012-04-16
    • 2016-02-28
    • 1970-01-01
    • 2016-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多