-->
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.  [ 8 posts ] 
Author Message
 Post subject: ClassCastException
PostPosted: Thu Jul 21, 2005 5:02 pm 
Newbie

Joined: Mon Jul 18, 2005 8:13 pm
Posts: 2
I run this query:

results = session.createQuery("SELECT p FROM ContactSheetPerson csp, Person p WHERE csp.id.personid = p.personid AND csp.id.contactsheetid=" + sheetId).list();

Where ContactSheetPerson is a bridge between person and contactSheet tables.

Everything works okay with the query it seems but when I attempt to dump the data in my jsp I get an error if any of the columns are blank (nulls are allowed everywhere but id and name). Its a mySql db. Here's the full exception:

java.lang.ClassCastException
at org.hibernate.type.StringType.toString(StringType.java:42)
at org.hibernate.type.NullableType.toLoggableString(NullableType.java:122)
at org.hibernate.type.CollectionType.toLoggableString(CollectionType.java:147)
at org.hibernate.pretty.Printer.toString(Printer.java:53)
at org.hibernate.pretty.Printer.toString(Printer.java:90)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(Abstrac
tFlushingEventListener.java:91)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventLi
stener.java:39)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:711)
at org.hibernate.impl.SessionImpl.prepareQueries(SessionImpl.java:895)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:885)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.eaton.ee.teamcontacts3.dao.ContactSheetDAO.getSheetsByTeam(ContactSheetDAO.java:168)
at com.eaton.ee.teamcontacts3.dao.teamDAO.getTeamById(teamDAO.java:46)
at com.eaton.ee.teamcontacts3.action.ViewTeam.execute(ViewTeam.java:54)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)

at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j
ava:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Standar
dPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Standar
dPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Standar
dPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Standar
dPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Standar
dPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Standar
dPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11P
rotocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Thread.java:536)
Hibernate: select team0_.teamId as teamId0_, team0_.name as name1_0_, team0_.description as descript
3_1_0_ from team team0_ where team0_.teamId=?


I tested by entering items in all the rows and sure enough it will output fine then. Just has problems when a field is left blank. Any suggestions? Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 23, 2005 1:07 pm 
Beginner
Beginner

Joined: Fri Feb 20, 2004 6:15 pm
Posts: 38
Do you have log4j for Hibernate set to DEBUG mode? I'm getting a similar error when I run in DEBUG mode, but if you set it to WARN then I don't get the error.

If you have it in DEBUG, try to see if the error still occurs when it's set to WARN. This may be a Hibernate bug.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 8:35 am 
Newbie

Joined: Mon Jul 18, 2005 8:13 pm
Posts: 2
Actually log4j isn't set up on this project. Its kinda a small test project to see if we want to use hibernate for an upcoming project. I've been meaning to get log4j up. Maybe i'll do that today. I'll post again if anything changes once logging is in place. Thanks.


Top
 Profile  
 
 Post subject: debug level error
PostPosted: Wed Jul 27, 2005 1:36 pm 
Newbie

Joined: Tue Jul 12, 2005 11:31 am
Posts: 4
Location: Nashville, TN USA
I also was getting an error due to the loglevel being set to debug. I thought, bug!, but waited. I didn't actually try changing the log level. In my case, this was the first time I had to load a persistent class with a single-column ID. I am mapping legacy data and most of it has composite keys. The other simple-ID persistent classes are associations I never have to look up. All along I had either been using the persistent class itself or a key class to do lookups. Instead the MessageHelper.infoString() call in org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad() was instructive in showing me that Hibernate was expecting a String ID (the type of my single ID column) rather than an ID of the persistent class itself. I modified my call to Session.load() to use a String ID and everything works. I assume this is as-intended behavior.

HTH,
Matt


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 8:31 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi

results = session.createQuery("SELECT p FROM ContactSheetPerson csp, Person p WHERE csp.id.personid = p.personid AND csp.id.contactsheetid=" + sheetId).list();


Where exactly you can get an error?

1) in the List results?

2) while casting to an Object?

I think session.createQuery will give you a Object Array. If you cast it to an Object in the JSP you will get an ClassCastException.

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 1:37 pm 
Newbie

Joined: Wed Mar 08, 2006 9:36 am
Posts: 4
Well, I wish turning off the debugger worked for me, but unfortunately it had no effect (I still get the same error). Like Matt, I also work with a legacy database, and it not only lacks surrogate keys and profusely uses composite keys, but also has no foreign key constraints. I am not really surprised to have problems mapping sorted collections correctly under the circumstances, but what drives me insane is that these errors are so difficult to trace. I have a good feeling about where the culprit code sits, but the problem does not manifest itself until the next flush. Even surrounding the suspect code with flush statements does not narrow it down enough to know what exactly causes the class cast exception.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 10:37 am 
Newbie

Joined: Fri Jan 06, 2006 5:29 pm
Posts: 16
I am getting the same error when trying to load a table with nullable string columns...I get this when I go to access the String in a getter:

Code:
java.lang.ClassCastException
   at org.hibernate.type.StringType.toString(StringType.java:44)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:87)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
   at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
   at org.hibernate.loader.Loader.doQuery(Loader.java:661)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41)
   at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:82)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
   at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:820)
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:62)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
   at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 08, 2006 9:41 am 
Newbie

Joined: Fri Sep 15, 2006 3:12 pm
Posts: 2
I'm getting the same error, has this been resolved yet?

It was suggested to change the log level for hibernate, could you instruct me which file I need to change. I am using JBOSS.

Thanks a lot.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.