Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in Hibernate Query

 
Anupam Dee
Ranch Hand
Posts: 42
Firefox Browser Tomcat Server Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this will be answered better in the ORM forum (where Hibernate questions are answered). Moving this to the ORM forum.
 
harshvardhan ojha
Ranch Hand
Posts: 157
1
Android Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anupam Dee
Ranch Hand
Posts: 42
Firefox Browser Tomcat Server Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah thanks folks. I used the Query object and changed the sql to "from Expenditure where...." and it worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic