我正在使用spring + hibernate,当我使用rich:upload
组件上传doc文件时出现错误,doc上传成功,但是当我点击确定它会出现以下错误。该字段为byte[]
doc;
org.springframework.dao.InvalidDataAccessResourceUsageException
: 无法插入: [com.eTender.model.UploadDoc
]; 嵌套异常是org.hibernate.exception.DataException
: 无法插入: [com.eTender.model.UploadDoc
]
答案 0 :(得分:0)
解决了问题。
public void fileUploadListner(UploadEvent event) throws Exception {
UploadItem item = event.getUploadItem();
File imageFilePath = item.getFile();
uploadDocDataBean.setDocname(item.getFileName());
uploadDocDataBean.setDocsize(String.valueOf(item.getFileSize()));
InputStream fileInputStream = new FileInputStream(imageFilePath);
byte[] data = new byte[(int)imageFilePath.length()];
fileInputStream.read(data, 0, (int)imageFilePath.length());
fileInputStream.close();
uploadDocDataBean.setDoc(data);
}