浏览 3599 次
锁定老帖子 主题:框架移植后出现上传失败的问题
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-03-26
vm文件 <form action="souupload.action" method="post" enctype="multipart/form-data" name="uploadsource"> 文件名:<input name="fileName" type="text" class="btn_grey"> <input type="hidden" name="id" value="$!req.getSession().getAttribute("customer").id"> <input name="EDITFILE" type="file" class="btn_grey"> <input type="submit" name="Submit" value="上传文件" class="btn_grey"> <input type="button" value=" 退 出 " class="btn_grey" onclick="javaScript:window.location.href='index.action';" > </form> 上传Action中的代码如下: FileUploadAction private int fileId=-1; private int id; private String fileName; private EricFileAware ericfileAware; public String execute()throws Exception{ try { HttpServletRequest req = ServletActionContext.getRequest(); MultiPartRequestWrapper wrapper = (MultiPartRequestWrapper) req; File doc = null; try { File[] docs = wrapper.getFiles("EDITFILE"); System.out.println(docs.length); if (docs != null && docs.length > 0) { doc = docs[0]; FileInputStream in = new FileInputStream(doc); Blob blob = Hibernate.createBlob(in); int fileSize = (int) doc.length(); cn.kyvin.shop.webshop.object.EricFile ericFile=new cn.kyvin.shop.webshop.object.EricFile(); if(this.fileId>0){ }else{ ericFile.setFileName(this.fileName); ericFile.setFileSize(new Integer(fileSize)); ericFile.setFileData(blob); this.ericfileAware.insertFile(ericFile); } } } finally { doc.delete(); } this.addActionMessage("^o^EricZone资源上传成功^o^"); return SUCCESS; } catch (Exception e) { return INPUT; } } FileAware接口中方法如下: ... public EricFile insertFile(EricFile file) throws ServicesException; Fileimpl实现类中代码如下: 该实现类扩展了一下 HibernateDaoSupport 这个类中的方法 public EricFile insertFile(EricFile file) throws ServicesException { try { Session session =this.getSession(); Transaction tx = null; byte[] buffer = new byte[1]; buffer[0] = 1; try { tx = session.beginTransaction(); Blob blob = file.getFileData(); file.setFileData(Hibernate.createBlob(buffer)); session.save(file); session.flush(); session.refresh(file, LockMode.UPGRADE); BLOB blobTemp = (BLOB) file.getFileData(); OutputStream out = blobTemp.getBinaryOutputStream(); InputStream in = blob.getBinaryStream(); byte[] data = new byte[(int) in.available()]; in.read(data); out.write(data); out.flush(); in.close(); out.close(); session.flush(); tx.commit(); } catch (Exception he) { if (tx != null) tx.rollback(); } finally { session.close(); } } catch (HibernateException he) { } return file; } 通过这些程序我上传到oracle数据库中的时候会出现这个错误,当然hbm.xml文件肯定配置没问题 错误提示: 09:15:30,156 ERROR [http-8562-Processor23] SessionImpl:2400 - Could not synchronize database state with session 09:15:30,203 ERROR [http-8562-Processor23] JDBCTransaction:108 - Could not toggle autocommit net.sf.hibernate.HibernateException: Session is closed 出现这样的问题该如何解决 我也想过通过this.getSessionFactory.openSession来打开session,可是一点用都没有 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-03-26
把事务处理交给spring来做试试
|
|
返回顶楼 | |
发表时间:2007-03-26
刚使用spring不久,我好像已经把事务都已经交给了spring来处理,在配置文件中有做配置,刚修改了下 但是总是在运行到 session.flush();
session.refresh(file, LockMode.UPGRADE);的时候会出现事务回滚掉 能贴出你想法的代码吗 谢谢了 |
|
返回顶楼 | |
发表时间:2007-03-26
我看你代码中有
tx = session.beginTransaction(); 如果用spring配的事务,这些应该就不用了啊! <tx:annotation-driven/> <aop:aspectj-autoproxy/> <aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* org.service.*Manager.*(..))" advice-ref="txAdvice"/> </aop:config> <tx:advice id="txAdvice"> <tx:attributes> <tx:method name="get*" read-only="true"/> <tx:method name="find*" read-only="true"/> <tx:method name="*"/> </tx:attributes> </tx:advice> |
|
返回顶楼 | |
发表时间:2007-03-26
我是这样配的 看来真的得看看spring了 对你的配置有些许不懂
<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory" /> </property> </bean> <bean id="baseTxProxy" lazy-init="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"> <property name="transactionManager"> <ref bean="transactionManager" /> </property> <property name="transactionAttributes"> <props> <prop key="insert*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> 同时我有尝试过把那段去掉 但是依旧出现类似的错误: Session is closed; nested exception is net.sf.hibernate.HibernateException: Session is closed net.sf.hibernate.HibernateException: Session is closed 我先尝试用你的试试^o^ |
|
返回顶楼 | |