Search code examples
hibernatespringrichfaces

i am using spring+hibernate and i m getting error : org.springframework.dao.InvalidDataAccessResourceUsageException


i am using spring+hibernate and i m getting error when i upload doc file using rich:upload component, doc is uploaded sucessfully but when i click ok it gives following error. The field is byte[] doc;

org.springframework.dao.InvalidDataAccessResourceUsageException: could not insert: [com.eTender.model.UploadDoc]; nested exception is org.hibernate.exception.DataException: could not insert: [com.eTender.model.UploadDoc]


Solution

  • Problem Solved.

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