Skip to main content
August 27, 2009
Question

CF8 with Java CFX / Hibernate - ClassCastException

  • August 27, 2009
  • 1 reply
  • 767 views

Hi,

I don't know if anyone can throw any light onto this?  I have a bunch of Java code that uses Hibernate to interact with the database. I am trying to put a CF web front on to display some information.  I wrote a very small Java CFX as a gateway into my Java codebase.  Somewhat surprisingly to me it was actually very easy to get it more-or-less working.  In fact, if I use non-generics code I can display values straight from my database onto a webpage.

I have a valid Hibernate Query object that I call .list on.  The list contains Country objects (say).  If I loop over the list as 'objects' and ay call the toString method (which in turns calls Country specific methods) it works fine, however if I try and cast to a Country object I get a ClassCastException saying it cannot cast Country to Country.

The only thing I can think of is that the 'two' Country classes (conceptually they is just a single class, of course) cannot be cast to each other because they were loaded by different classloaders.

Anyone have any idea?

Cheers,

Andy

I am using CF8, Java 1.6 and Hibernate 3.

This topic has been closed for replies.

1 reply

August 27, 2009

Okay, my bad.  Maybe noone else will have this problem, but rather than delete my questions  ...

So I had accidentally left one of my jars in the cfroot/lib directory (so it was being loaded by the boot class loader).  When I removed it it was correctly picked up from the runtime directory (using the App class loader).

Inspiring
August 27, 2009

Glad you solved it .. and thanks for posting a follow-up!