首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

框架移植后出现下传失败的有关问题

2012-11-03 
框架移植后出现上传失败的问题最近我从原先的webwork+hibernate框架中转到现在的webwork+hibernate+spring

框架移植后出现上传失败的问题
最近我从原先的webwork+hibernate框架中转到现在的webwork+hibernate+spring框架,当处理上传的时候我采用了原先的方法的来处理上传,
vm文件

<form action="souupload.action" method="post" enctype="multipart/form-data" name="uploadsource">  文件名:<input name="fileName" type="text" name="id" value="$!req.getSession().getAttribute("customer").id">  <input name="EDITFILE" type="file"  name="Submit" value="上传文件" value=" 退 出 " 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 session09:15:30,203 ERROR [http-8562-Processor23] JDBCTransaction:108 - Could not toggle autocommitnet.sf.hibernate.HibernateException: Session is closed

出现这样的问题该如何解决 我也想过通过this.getSessionFactory.openSession来打开session,可是一点用都没有tx = session.beginTransaction();
如果用spring配的事务,这些应该就不用了啊!

<tx:annotation-driven/><aop:aspectj-autoproxy/><aop:config proxy-target-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>

<bean id="transactionManager" /></property></bean><bean id="baseTxProxy" lazy-init="true" 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 closednet.sf.hibernate.HibernateException: Session is closed

我先尝试用你的试试^o^

热点排行