• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.ClassCastException: org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFil

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

Iam using a File Upload Control in my jsp and have created an action against it...I'm trying to save the filePath in the database with the help of getHibernateTemplate().saveOrUpdate() method..whic is throwing this exception: -

exception

javax.servlet.ServletException: org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFile
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:520)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:427)
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:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

java.lang.ClassCastException: org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFile
org.hibernate.type.StringType.toString(StringType.java:44)
org.hibernate.type.NullableType.toLoggableString(NullableType.java:218)
org.hibernate.pretty.Printer.toString(Printer.java:53)
org.hibernate.pretty.Printer.toString(Printer.java:90)
org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:97)
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:693)
com.EMS.EmployeeCRUD.dao.EmpDAOImpl.saveOrUpdate(EmpDAOImpl.java:22)
com.EMS.EmployeeCRUD.action.AddEmployeeAction.execute(AddEmployeeAction.java:54)
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:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

In order to clear all the doubts...iam using hsqldb as database......

public class AddEmployeeAction extends Action {

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
System.out.println("Welcome to add Employee");
FileOutputStream outputStream = null;
FormFile myFile = null;

AddUpdateEmployeeForm frm = (AddUpdateEmployeeForm)form;
Employee emp = new Employee();
String usrname = frm.getUsername();
myFile = frm.getMyFile();
System.out.println("File is-->" + myFile);
try{
String fileName = myFile.getFileName();
String filePath = getServlet().getServletContext().getRealPath("/")+"fileAttachment"+"\\";
File fileToCreate = new File(filePath,fileName);
outputStream =new FileOutputStream(fileToCreate);
outputStream.write(myFile.getFileData());
}catch(Exception e){
System.out.println("Exception-->" + e);
}

System.out.println("UserName-->" + usrname);
System.out.println("Address-->" + frm.getAddress());
BeanUtils.copyProperties(frm, emp);
EmpDAO empDao = (EmpDAO)BeanFinder.getBean(BeanFinder.getContext(request),"empDao");
empDao.saveOrUpdate(emp);
System.out.println("Hello World----");
return mapping.findForward("success");

}

}

DAO Method
public void saveOrUpdate(Employee emp){
try{
System.out.println("Welcome to Save or Update DAO Method");
getHibernateTemplate().saveOrUpdate(emp);
}catch(RuntimeException e){
throw(e);
}
}
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to javaranch,
Please put code tag for your code, that will help to understand code easily....
 
His brain is the size of a cherry pit! About the size of this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic