如何使字段成为 BLOB 而不是 TINYBLOB?
我的映射如下:
private byte[] ImageBytes;
public BufferedImage getImage() {
InputStream in = new ByteArrayInputStream(ImageBytes);
try {
return ImageIO.read(in);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void setImage(BufferedImage image) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
ImageIO.write(image, "PNG" /* for instance */, out);
} catch (IOException e) {
throw new RuntimeException(e);
}
ImageBytes = out.toByteArray();
}
它会导致 Hibernate 在 MySQL 中创建不适合图像的 TINYBLOB 字段。
如何让它使用 BLOB?
下面的回答
@Lob(type = LobType.BLOB)
不起作用,因为@Lob
注释在我的库中没有参数。
此外,我不想使用特定于 ORM 或特定于 DBMS 的注释。