java 数据截断错误 - 列的数据太长
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10329356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Data truncation error - Data too long for column
提问by csaadaam
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:
但是,一些文件(65-70k 大小)插入正常,但大多数都会出现错误:
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.
我已经检查过,在创建实体之前,尺寸是正确的。
回答by vinodn
According to JPA doc "length" is only used for String properties.
根据 JPA 文档,“长度”仅用于字符串属性。
(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
如果您使用工具自动生成 DDL .. 您可以使用“columnDefinition”属性
@Column(columnDefinition = "LONGBLOB")
private byte[] content;