Data truncation error. The data is too long for the column.

Interestingly, in essence:

public static final int maxContentSize = 2097152; //2Mb
@Lob
@Column(length=maxContentSize)
private byte[] content;
@Column(length = 100)
private String mimetype;
@Column(length = 50)
private String fileName;

However, some files (size 65-70k) are inserted into the norm, but most of them get an error:

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'CONTENT' at row 1

I checked before creating objects, the dimensions are correct.

+5
source share
1 answer

According to JPA, doc "length" is used only for String properties.

(Optional) The length of the column. (Only applicable if a column with a row is used).

If you automatically generate DDL using the tool, you can use the columnDefinition attribute

@Column(columnDefinition = "LONGBLOB") 
private byte[] content;
+7
source

All Articles