csaadaam
csaadaam

Reputation: 73

Data truncation error - Data too long for column

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.

Upvotes: 5

Views: 15816

Answers (1)

kkumar
kkumar

Reputation: 355

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;

Upvotes: 6

Related Questions