File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassCastException - Hibernate - PersistentSet - Newbie needs a bit of help
 
Similar Threads
not able to get ObjectMessage at the JMS listner
PersistentSet issue while using GWT+Spring+Hibernate+Gilead
Primitive typecasting
nullpointerexception when trying to set object field?
sort PersistentSet