This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting a ClassCastException upon executing getHibernateTemplate().find(

 
Kim Kantola
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • 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


 
Hong Anderson
Ranch Hand
Posts: 1936
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should debug StringType to see what actually happened.
 
Kim Kantola
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic