• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in Hibernate Query

 
Ranch Hand
Posts: 42
Firefox Browser Tomcat Server Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 157
1
Android MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah thanks folks. I used the Query object and changed the sql to "from Expenditure where...." and it worked.
 
reply
    Bookmark Topic Watch Topic
  • New Topic