Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

seam file upload to postgres bytea column " column is bytea but expression is of type bigint"

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

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

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

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;
}
like image 484
mcgyver5 Avatar asked Feb 02 '12 14:02

mcgyver5


2 Answers

change @Lob annotation with @Table 



   instead of this ; 
    **@Lob**
    @Column(name = "letter_template_text")
    @Basic(fetch = FetchType.LAZY)
    private byte[] icon;

    write ;
    
    **@Type(type="org.hibernate.type.BinaryType")**
    @Column(name = "letter_template_text")
    @Basic(fetch = FetchType.LAZY)
    private byte[] icon;
like image 87
talhaakkoc Avatar answered Sep 19 '22 11:09

talhaakkoc


For me it's working with type bytea in Postgres database.

@Lob
@Type(type="org.hibernate.type.BinaryType")
@Column(name = "photo")
private byte[] photo;

//and get and set
like image 45
Alessandro Avatar answered Sep 19 '22 11:09

Alessandro