我的控制器類是越來越休眠異常,當我上傳圖片
@RequestMapping(value = "/profilePictureUpload", method = RequestMethod.POST)
public String handleFormUpload(@RequestParam("fileExtension") String fileExtension, @RequestParam("file") MultipartFile file,HttpServletRequest request) {
logger.info("In add profile Picture Upload");
String mediaResponse=null;;
try {
String token = request.getHeader("authToken");
System.out.println("+++++++++++++++token+++++++++++++++++++"+token);
User user = userDao.findUserByAuthToken(token);
System.out.println("+++++++++++++++USER+++++++++++++++++++"+user);
System.out.println("+++++++++++++++file.getBytes()+++++++++++++++++++"+file.getBytes());
if (user != null) {
Physician physicain=physicainDao.findPhysicianById(user.getPhysicianId().getPhysicianId());
String fileStoragPath=userOriginalServerPath+"/"+physicain.getPhysicianId();
File file1=new File(fileStoragPath);
file1.mkdirs();
String filePath=fileStoragPath+"/"+physicain.getPhysicianId()+System.currentTimeMillis()+fileExtension;
FileOutputStream fileOuputStream =new FileOutputStream(filePath);
fileOuputStream.write(file.getBytes());
fileOuputStream.close();
/**
* Creating thumbnail for media upload
*/
File thumbnailPath=new File(userThumbnailFilePath+physicain.getPhysicianId());
thumbnailPath.mkdirs();
String thumbnail_path=physicain.getPhysicianId()+"/"+physicain.getPhysicianId()+System.currentTimeMillis()+fileExtension;
Thumbnails.of(new File(filePath)).size(75, 75).toFile(new File(userThumbnailFilePath+thumbnail_path));
physicain.setProfileImage("MedikmUserPicture/thumbnail/"+thumbnail_path);
physicainDao.update(physicain);
mediaResponse="MedikmUserPicture/thumbnail/"+thumbnail_path;
}else{
mediaResponse=MedikmConstants.USER_INVALID_AUTHENTICATION__MESSAGE;
}
System.out.println("================mediaResponse============"+mediaResponse);
return mediaResponse;
}
catch(Exception ex){
ex.printStackTrace();
logger.error("Error in media tag Method :"+ex);
return mediaResponse=MedikmConstants.USER_INVALID_AUTHENTICATION__MESSAGE;
}
}
,並通過上傳圖像獲取休眠例外像
org.hibernate.exception.DataException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:102)
圖像獲取成功上傳,但不知道爲什麼我收到這個醫生類的例外字段名稱是我映射
@Column(name = "Profile_Image")
private String profileImage;
請幫我讓我從這個例外中解脫出來。
你是不是想上傳圖像作爲字符串?那是錯的。將它保存爲字節數組。多部分文件具有getBytes方法,請使用它。其次,您必須禁用批量更新以查看實際錯誤併發布更多錯誤信息。最後,您的控制器方法中有太多的邏輯,將其移至服務層。 –
你爲回覆異常是數據截斷:數據太長的'Profile_Image'列在 2015-09-16 17:02:09,598錯誤[org.hibernate.event.def.AbstractFlushingEventListener](http-apr-8080-exec -4) - 無法使數據庫狀態與sessio同步 org.hibernate.exception.DataException:無法在org.hibernate的org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:102) 處執行JDBC批處理更新 。異常.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)' – Sumit
就像我說的,禁用你的配置中的批量更新,所以你會有錯誤正確。另外,不要在評論中發佈錯誤,編輯您的主帖並將它們放在那裏。 –