The interesting thing is that in the entity:
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 (65-70k size) are inserted OK, but most of them get the error:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'CONTENT' at row 1
I've checked, before creating the entities, the sizes are correct.
That error message means you are inserting a value that is greater than the defined maximum size of the column. The solution to resolve this error is to update the table and change the column size.
That error means the data is too large for the data type of the MySQL table column.
We normally call it as silent truncation and occur when we try to insert string data (varchar, nvarchar, char, nchar) into more than the size of the column. If we are dealing with the huge amount of data with lots of columns, if we get any error it becomes difficult to find out which column, data caused the issue.
What is “String or binary data would be truncated” One of the most common SQL Server errors, the message “String or binary data would be truncated” occurs when a value is trying to be inserted or updated in a table and it is larger than the maximum field size.
According to JPA doc "length" is only used for String properties.
(Optional) The column length. (Applies only if a string-valued column is used.)
If you are automatically generating your DDL using a tool.. you can use "columnDefinition" attribute
@Column(columnDefinition = "LONGBLOB")
private byte[] content;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With