框架移植后出现上传失败的问题

最近我从原先的webwork+hibernate框架中转到现在的webwork+hibernate+spring框架,当处理上传的时候我采用了原先的方法的来处理上传,
vm文件
[code]
<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" οnclick="javaScript:window.location.href='index.action';" >
</form>
[/code]
上传Action中的代码如下:
FileUploadAction
[code]
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;
}

}
[/code]
FileAware接口中方法如下:
[code]
...
public EricFile insertFile(EricFile file) throws ServicesException;
[/code]
Fileimpl实现类中代码如下:
该实现类扩展了一下 HibernateDaoSupport 这个类中的方法
[code]

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;
}
[/code]
通过这些程序我上传到oracle数据库中的时候会出现这个错误,当然hbm.xml文件肯定配置没问题
错误提示:
[code]
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
[/code]
出现这样的问题该如何解决 我也想过通过this.getSessionFactory.openSession来打开session,可是一点用都没有
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值