如何使字段成为 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 的注释。
最佳答案
你可以这样试试;
@Lob
@Column(name="IMAGE", nullable=false, columnDefinition="blob")
private byte[] imageBytes;
并确保您的图像数据类型是 BLOB
。
关于java - 如何使字段成为 BLOB 而不是 TINYBLOB?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12475035/