Hi Guys I am sitting with this exception for almost the whole day . No clue about how to solve this .
The following piece of code while running is giving me classcast exception. We are using Jboss 6 and Hibernate 3 to run this code. The full stack trace is below
String sql = "select sarthakModel from SarthakModel customerModel WHERE objId="+175194003; Query query = session.createQuery(sql); List list = query.list;
SarthakModel sarthakModel = (SarthakModel)obj;
System.out.println("After the casting has been done and the value from caswted class is "+sarthakModel.getCompanyUrl());
The below line of code is giving false .
System.out.println("The class of the object retrieved is "+list.get(0).getClass().isInstance(customerModel1));
I thought that there might be two versions of the same class file getting included so compile time/run time error is happening. But I checked and there is only one class file of the SarthakModel class.
22:41:34,685 ERROR [STDERR] java.lang.ClassCastException: com.ivizsecurity.cmp.model.SarthakModel cannot be cast to deafult.cmp.model.SarthakModel 22:41:34,686 ERROR [STDERR] at default.cmp.dao.CmpDao.getCustomers(Unknown Source) 22:41:34,686 ERROR [STDERR] at default.cmp.business.AppWSRequestRouter.directCall(Unknown Source) 22:41:34,686 ERROR [STDERR] at default.cmp.webservices.CustomerRestApi.getCustomers(Unknown Source) 22:41:34,686 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 22:41:34,686 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 22:41:34,686 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 22:41:34,686 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597) 22:41:34,687 ERROR [STDERR] at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140) 22:41:34,687 ERROR [STDERR] at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:252) 22:41:34,687 ERROR [STDERR] at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:217) 22:41:34,687 ERROR [STDERR] at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:206) 22:41:34,687 ERROR [STDERR] at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:503) 22:41:34,687 ERROR [STDERR] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:480) 22:41:34,687 ERROR [STDERR] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) 22:41:34,687 ERROR [STDERR] at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:207) 22:41:34,687 ERROR [STDERR] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) 22:41:34,688 ERROR [STDERR] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) 22:41:34,688 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 22:41:34,688 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) 22:41:34,688 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) 22:41:34,688 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) 22:41:34,688 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 22:41:34,688 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) 22:41:34,689 ERROR [STDERR] at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) 22:41:34,689 ERROR [STDERR] at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) 22:41:34,689 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) 22:41:34,689 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) 22:41:34,689 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 22:41:34,689 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 22:41:34,689 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) 22:41:34,689 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 22:41:34,689 ERROR [STDERR] at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) 22:41:34,690 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) 22:41:34,690 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) 22:41:34,690 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) 22:41:34,690 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) 22:41:34,690 ERROR [STDERR] at java.lang.Thread.run(Thread.java:662)
After some more debugging what I found out that if I insert the record and read the record in the same deployment of the application then it is working fine.
However if the following sequence of events happen which is very very normal then this classCastException is happening :-
1) Application is deployed and the record is inserted. 2) Application is undeployed and re deployed again. 3) A read action is invoked on the application . 4) Then the exception is happening.
Does this ring a bell to any one ?
|