Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

ClassCastException - Hibernate - PersistentSet - Newbie needs a bit of help

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am running through a Hibernate Travel application and need some help with the following code. Everything works up until the line "trips4Person = (Trip[])personTrips.toArray();", where I receive a "java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ltravel.Trip;"



Trip and Person are java beans. I have debugged it to the last line and it all works ok, but for some reason the cast to Trip is not working.

Any help would be much appreciated!

Thanks.
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
toArray() returns an Object[] which cannot be typecast to Trip[] as Object is not a subclass of Trip. But maybe you can use System.arraycopy() (but am not sure).
 
Christopher Frankland
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sridhar Santhanakrishnan wrote:toArray() returns an Object[] which cannot be typecast to Trip[] as Object is not a subclass of Trip. But maybe you can use System.arraycopy() (but am not sure).



Thanks Sridhar. Forgot to pass Trip into personTrips.toArray() as a parameter.
 
Are we home yet? Wait, did we forget the tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic