-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: hibernate classcastexception [BUG in Hibernate ??]
PostPosted: Tue Jun 07, 2011 3:38 am 
Newbie

Joined: Tue Jun 07, 2011 3:33 am
Posts: 2
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 ?


Top
 Profile  
 
 Post subject: Re: hibernate classcastexception [BUG in Hibernate ??]
PostPosted: Tue Jun 07, 2011 4:36 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
com.ivizsecurity.cmp.model.SarthakModel cannot be cast to deafult.cmp.model.SarthakModel


Seems like you have two different SarthakModel classes in two different packages. Maybe you are simply using the incorrect class when you should be using the other.


Top
 Profile  
 
 Post subject: Re: hibernate classcastexception [BUG in Hibernate ??]
PostPosted: Tue Jun 07, 2011 4:59 am 
Newbie

Joined: Tue Jun 07, 2011 3:33 am
Posts: 2
No , those kind of silly things have already been looked for :(

This is the same exception occuring with 2-3 different developers in their respective machines who are working on completely different set of model classes and code .

And everything works fine if I do the write and read inside same deployment of the app in Jboss.


Top
 Profile  
 
 Post subject: Re: hibernate classcastexception [BUG in Hibernate ??]
PostPosted: Tue Jun 07, 2011 4:35 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
What do you mean with "no"? The exception clearly mentions two different packages... Which one have you mapped with Hibernate?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.