JPA, Mysql Blob returns data too long
I use below and it works for images
@Lob
@Column(name = "file", columnDefinition = "LONGBLOB")
private byte[] file;
It all depends on the column type used for the picture
column. Depending on your needs, use a:
TINYBLOB
: maximum length of 255 bytesBLOB
: maximum length of 65,535 bytesMEDIUMBLOB
: maximum length of 16,777,215 bytesLONGBLOB
: maximum length of 4,294,967,295 bytes
Note that if you generate your table from the JPA annotations, you can "control" the type MySQL will use by specifying the length
attribute of the Column
, for example:
@Lob @Basic(fetch = FetchType.LAZY)
@Column(length=100000)
private byte[] picture;
Depending on the length
, you'll get:
0 < length <= 255 --> `TINYBLOB`
255 < length <= 65535 --> `BLOB`
65535 < length <= 16777215 --> `MEDIUMBLOB`
16777215 < length <= 2³¹-1 --> `LONGBLOB`