微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

postgresql – 接缝文件上传到postgres bytea列“列是bytea但表达式是bigint类型”

紧随 this example之后,我正在上传一个文件并尝试存储到postgresql bytea列中.

这是错误(前两个输出是在尝试INSERT之前输出bean属性的日志语句:

SAGE 1 — action.registration.LetterTemplateHome – content type: text/xml

SAGE 1 — action.registration.LetterTemplateHome – letterTemplateText: [B@48c7aaef

SAGE 1 — action.registration.LetterTemplateHome – contents as String: xml version=”1.0″ encoding=”UTF-8″ standalone=”yes” …. etc

SAGE 1 — org.hibernate.util.JDBCExceptionReporter – Batch entry 0 insert into letter_template (content_type,file_name_template,fileSize,letter_template_name,letter_template_text,letter_template_id) values (‘text/xml’,‘letterDate.xml’,‘0’,‘yu’,‘37078’,‘202’) was aborted. Call getNextException to see the cause.

SAGE 1 — org.hibernate.util.JDBCExceptionReporter – ERROR: column “letter_template_text” is of type bytea but expression is of type bigint
Hint: You will need to rewrite or cast the expression.
Position: 162

这里是如何在bean中定义字段:

private byte[] letterTemplateText;

@Lob
@Column(name = "letter_template_text")
@Basic(fetch = FetchType.LAZY)
public byte[] getLetterTemplateText() {
    return this.letterTemplateText;
}

public void setLetterTemplateText(byte[] letterTemplateText) {
    this.letterTemplateText = letterTemplateText;
}
我怀疑Hibernate正在尝试使用Postgresql的“大对象”方法,该方法涉及将OID“句柄”存储到表中的文件中.一些例子阅读: http://virgo47.wordpress.com/2008/06/13/jpa-postgresql-and-bytea-vs-oid-type/

如果您想坚持使用bytea列(这在sql端使用起来相当简单),请使用BinaryType映射列.见:proper hibernate annotation for byte[]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐