This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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.
 
wood burning stoves
 
subject: ClassCastException - Hibernate - PersistentSet - Newbie needs a bit of help
 
Similar Threads
sort PersistentSet
PersistentSet issue while using GWT+Spring+Hibernate+Gilead
Primitive typecasting
nullpointerexception when trying to set object field?
not able to get ObjectMessage at the JMS listner