接缝文件上传到postgres bytea列“列是bytea,但表达式的类型是bigint。 [英] seam file upload to postgres bytea column " column is bytea but expression is of type bigint"

查看:148
本文介绍了接缝文件上传到postgres bytea列“列是bytea,但表达式的类型是bigint。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

紧随此示例之后,我正在上传一个小文件,并尝试将其存储到postgresql bytea列中。

Closely following this example, I'm uploading a small file and trying to store into postgresql bytea column.

这里是错误(前两个输出是记录语句,在尝试执行INSERT之前输出bean的属性:

Here is error (first two outputs are logging statements outputting attributes of bean before the INSERT is attempted:


SAGE 1-action.registration.LetterTemplateHome-内容类型:文本/ xml

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

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

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

SAGE 1-action.registration.LetterTemplateHome-内容为字符串:xml version = 1.0 encoding = UTF-8 standalone = yes .... etc

SAGE 1 -- action.registration.LetterTemplateHome - contents as String: xml version="1.0" encoding="UTF-8" standalone="yes" .... etc

SAGE 1 – org.hibernate.util.JDBCExceptionReporter-批处理条目0插入letter_template(content_type,file_name_template,fileSize,letter_template_name,letter_template_text, letter_template_id)值( text / xml, letterDate.xml, 0, yu, 37078, 202)被中止。调用getNextException以查看原因。

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-错误:列 letter_template_text的类型为bytea,但表达式为类型:bigint
提示:您将需要重写或强制转换表达式。
位置:162

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中定义字段的方式:

here is how the field is defined in the 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/

I suspect that Hibernate is trying to use the "large object" method with PostgreSQL, which involves storing an OID "handle" to the file in the table. Some example reading: http://virgo47.wordpress.com/2008/06/13/jpa-postgresql-and-bytea-vs-oid-type/

如果要坚持使用仅一个bytea列(这在SQL端使用起来相当简单),请使用BinaryType映射该列。请参阅:为字节提供适当的休眠注释[]

If you want to stick with just using a bytea column (and this is considerably simpler to work with on the SQL side), use BinaryType to map the column. See: proper hibernate annotation for byte[]

这篇关于接缝文件上传到postgres bytea列“列是bytea,但表达式的类型是bigint。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆