GeeCON Prague 2014*
The moose likes Object Relational Mapping and the fly likes ClassCastException - Hibernate - PersistentSet - Newbie needs a bit of help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "ClassCastException - Hibernate - PersistentSet - Newbie needs a bit of help" Watch "ClassCastException - Hibernate - PersistentSet - Newbie needs a bit of help" New topic
Author

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

Christopher Frankland
Ranch Hand

Joined: Jan 22, 2005
Posts: 42
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.
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
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

Joined: Jan 22, 2005
Posts: 42
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.
 
GeeCON Prague 2014
 
subject: ClassCastException - Hibernate - PersistentSet - Newbie needs a bit of help