我正在使用spring + hibernate并且我收到错误:org.springframework.dao.InvalidDataAccessResourceUsageException

时间:2010-08-11 04:43:16

标签: hibernate spring richfaces

我正在使用spring + hibernate,当我使用rich:upload组件上传doc文件时出现错误,doc上传成功,但是当我点击确定它会出现以下错误。该字段为byte[] doc;

  

org.springframework.dao.InvalidDataAccessResourceUsageException:   无法插入:   [com.eTender.model.UploadDoc];   嵌套异常是   org.hibernate.exception.DataException:   无法插入:   [com.eTender.model.UploadDoc]

1 个答案:

答案 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);
}