【发布时间】:2015-08-19 04:23:22
【问题描述】:
我正在使用 spring data jpa 和 hibernate 从数据库表中检索实体。实体字段之一是位于文件系统上的图像的路径。是否可以将图像作为字节数组加载到实体中?例如
@Entity
@Table(name="Users")
public class User
{
@Id
@GeneratedValue
int id;
String name;
String pictureName;
@Transient
byte[] image;
// other properties
public void setPictureName(String pictureName)
{
String path="D:\\images\\";
File f = new File(path + pictureName);
this.image = new byte[(int)f.length()];
FileUtility.toByteArray(f,this.image); //custom class
this.picture = picture;
}
//other stuff
}
我用 JPA 尝试过,但字节数组图像字段总是为空,而其他一切都很好。
【问题讨论】: