• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Getting a ClassCastException upon executing getHibernateTemplate().find(

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should debug StringType to see what actually happened.
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic