I\'ve got some byte[]
fields in my entities, e.g.:
@Entity
public class ServicePicture implements Serializable {
private static final long s
In our case we had to use the following syntax:
public class CcpArchive
{
...
private byte[] ccpImage;
...
@Lob
@Column(nullable = false, name = "CCP_IMAGE", columnDefinition="BINARY(500000)")
public byte[] getCcpImage()
{
return ccpImage;
}
...
}
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 bytesNote 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`