Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data truncation error - Data too long for column

Tags:

java

mysql

jpa

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.

like image 822
csaadaam Avatar asked Apr 26 '12 07:04

csaadaam


People also ask

How do I fix a data too long for a column?

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.

What is Data truncated for column?

That error means the data is too large for the data type of the MySQL table column.

What is data truncation error?

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 truncation error in SQL Server?

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.


1 Answers

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;
like image 136
vinodn Avatar answered Sep 24 '22 16:09

vinodn