java中ssh批量上传_ssh 框架批量保存对象时hibernate报错

使用ssh框架,批量插入数据时报如下错误:

java.lang.RuntimeException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.DataException: Could not execute JDBC batch update

com.renren.web.action.AlbumAction.addPhotos(AlbumAction.java:137)

sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

java.lang.reflect.Method.invoke(Method.java:497)

org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)

org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)

org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)

org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)

org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)

org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)

javax.servlet.http.HttpServlet.service(HttpServlet.java:661)

javax.servlet.http.HttpServlet.service(HttpServlet.java:742)

org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)

org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)

org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

批量保存的action:

AlbumForm af = (AlbumForm) form;

Users u= (Users)request.getSession().getAttribute("loginInfo");

String userId =u.getId().toString();

String albumId = request.getParameter("albumId");

Album album = (Album) photoServiceImp.findById(Album.class, Integer.valueOf(albumId));

String webSavePath = "/images/upload/"+u.getId()+"/album/"+albumId;

String upPath = request.getSession().getServletContext().getRealPath(webSavePath);

System.out.println(albumId+"--"+userId+"\r\n"+upPath+"\r\n");

System.out.println("文件个数:"+af.getAllPhoto().size());

//循环上传照片

for (int i = 0; i < af.getAllPhoto().size(); i++) {

Photo p = new Photo();

FormFile photo = af.getPhotos(i);

System.out.println(photo.getFileName());

try {

String saveName = MyFileStream.uploadFile(photo, upPath);

p.setAddTime(new Date());

p.setAlbum(album);

p.setPhoto(webSavePath+"/"+saveName);

System.out.println(webSavePath+"/"+saveName);

photoServiceImp.save(p);

System.out.println("添加的信息"+p.getId()+"--"+p.getAddTime());

System.out.println("Hashcode"+p.hashCode());

} catch (Exception e) {

// TODO: handle exception

throw new RuntimeException(e.getMessage());

}

}

//清空form中的photos数组列表

//af.clearPhotos();

return mapping.findForward("goOneAlbumUI");

photo表的主键生成策略是increment;实体类的配置文件,使用反向工程生成的。

为啥报批量更新失败,需要强制flush么???困扰许久

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值