aspose file tools*
The moose likes Spring and the fly likes Getting a ClassCastException upon executing getHibernateTemplate().find( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Getting a ClassCastException upon executing getHibernateTemplate().find(" Watch "Getting a ClassCastException upon executing getHibernateTemplate().find(" New topic
Author

Getting a ClassCastException upon executing getHibernateTemplate().find(

Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
Hello All,

In my java code, I create some Hibernate Query Language (HQL) and execute it as follows :


where the parameter patients is a java.util.List object of String values.

When this code is run, I do not get any SQL exceptions, but I do get a class Cast exception as follows :

java.lang.ClassCastException
at org.hibernate.type.StringType.toString(StringType.java:44)


I am new to Spring and Hibernate, maybe my problem is something obvious to you out there with more experience?
Thanks in advance,
Kim


Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
You should debug StringType to see what actually happened.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
I got past this, not sure if this is the only solution as I am so new to this, but I do know that what I changed did make the error go away.

The problem appeared to be here :



The object patients was a java.util.List. It looks like the find method of getHibernateTmeplate looks for an array there. I took my list of Strings, created an array of Strings ( String[] ) and passed that instead. This worked.

Kim
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting a ClassCastException upon executing getHibernateTemplate().find(