5

有趣的是,在实体中:

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;

但是,某些文件(65-70k 大小)插入正常,但大多数都收到错误:

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

我已经检查过,在创建实体之前,大小是正确的。

4

1 回答 1

7

根据 JPA doc,“长度”仅用于字符串属性。

(可选)列长度。(仅在使用字符串值列时适用。)

如果您使用工具自动生成 DDL.. 您可以使用“columnDefinition”属性

@Column(columnDefinition = "LONGBLOB") 
private byte[] content;
于 2012-04-26T08:36:29.637 回答