aspose file tools
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 RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "ClassCastException Hibernate " Watch "ClassCastException Hibernate " New topic

ClassCastException Hibernate

shriram iyer
Ranch Hand

Joined: Dec 10, 2003
Posts: 43

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 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(
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

Hemant Thard
Ranch Hand

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

Hibernate: select 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
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);

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


Naresh Waswani
I agree. Here's the link:
subject: ClassCastException Hibernate