wood burning stoves*
The moose likes Object Relational Mapping and the fly likes ClassCastException Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "ClassCastException Hibernate " Watch "ClassCastException Hibernate " New topic
Author

ClassCastException Hibernate

shriram iyer
Ranch Hand

Joined: Dec 10, 2003
Posts: 43
Greetings,

My hibernate configuration file is as follows



my hibernate mapping file is as follows



my bookpojo is as follows



my main class is as follows



when i run the program i am getting following error


Hibernate: select this_.name as y0_ from books this_
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to hiberbatchtest.BookPojo
at hiberbatchtest.Main.main(Main.java:17)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)


cheers
Hemant Thard
Ranch Hand

Joined: Dec 23, 2008
Posts: 122
Hi shriram,


Hibernate: select this_.name as y0_ from books this_


from this query, i think its clear that hibernate is returning only name property which is of type String.
That is why you are getting java.lang.ClassCastException.

if you want to retrieve the whole object remove this from from your criteria query.


here is the link you can refer to.




shriram iyer
Ranch Hand

Joined: Dec 10, 2003
Posts: 43
thanks
Waswani Naresh
Ranch Hand

Joined: May 01, 2008
Posts: 66
If you want to retrieve only the names than remove the below line.

BookPojo obj= (BookPojo) it.next();


You would actually get a List of String in this case which you can traverse over.

Regards,
Naresh


Naresh Waswani
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassCastException Hibernate
 
Similar Threads
Dialect class not found
data insert error
Cannot insert record into Database!
Getting unrequested nested query
Hibernate not inserting new record on SQL Server