Seam file upload to postgres bytea column "column istete, but expression is of type bigint"

Following this example , I upload a small file and try to save it in the postgresql bytea column.

Here is the error (the first two outputs are the logging operators that display the attributes of the bean before the INSERT attempt:

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: the column "letter_template_text" is of type bytea, but the expression is of type bigint Hint: you will need to rewrite or cast the expression. Position: 162

this is how a field is defined in a bin:

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; } 
+6
source share
3 answers

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

If you want to use only the bytea column (and it is much easier to work on the SQL side), use BinaryType to map the column. See: hibernation annotation for byte []

+4
source

A similar error may occur if you add <loadData/> with missing column tags inside and some CSV file, for example, with the path to the blob files in some CSV column used to populate the blob column in the table. It does not indicate "wow, you do not have columns in the loadData tag", but it is assumed that all csv columns are string data, and then gives the specified error (but writes column is bytea but expression is of type string ). You just need to explicitly specify all the table columns using the column tags and specify their data type.

+1
source

This does not really answer your question, but I thought I would share it anyway ...

There are two ways to store files using the database: in fact: saving the actual contents of the file (like you) and saving only the path to the file (and saving it to the actual file system).

I worked with both methods, and I preferred the latter for two reasons: I can move files to other hard drives, partitions, and even access them through a shared resource, and all I need to do is change the file paths to the databases . In addition, it makes database dumps (aka backups) much smaller and faster to execute.

0
source

Source: https://habr.com/ru/post/1394407/


All Articles