wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Problem in Hibernate Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem in Hibernate Query" Watch "Problem in Hibernate Query" New topic
Author

Problem in Hibernate Query

Anupam Dee
Ranch Hand

Joined: Oct 18, 2010
Posts: 42



This is a simple code to retrieve the expenditure from the expenditure table.
But I am getting ClassCastException Object can't be cast to Expenditure.
How to do it?
And when i used this code to print the result object, i am getting two objects..which is correct..
Now please help me how to do it? I just want to use it as a Expenditure object.
I have XML file expenditure.hbm.xml mapped to the table expenditure and the class is com.expensemanager.core.Expenditure so that i can call the methods over it.
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1083
    
  10

I think this will be answered better in the ORM forum (where Hibernate questions are answered). Moving this to the ORM forum.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157
    
    1

Hi Anupam, you are using here sql query. Thats why you are not getting it mapped to POJO. Wither map it to your pojo or use equivalent HQL query. Hope this will help you.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1649
    
    7

harshvardhan is correct. You are using native SQL, when what you want is to use HQL. I have included a link below that should get you started with getting your query converted to HQL.

http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#queryhq


[How To Ask Questions][Read before you PM me]
Anupam Dee
Ranch Hand

Joined: Oct 18, 2010
Posts: 42

Yeah thanks folks. I used the Query object and changed the sql to "from Expenditure where...." and it worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Hibernate Query