• 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 retrieving data with HQL

 
Ranch Hand
Posts: 51
Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to Hibernate. I am using Netbeans 6.9, Oracle 10G. I want to retrieve data from a table and want to display it.
My table named Product has 3 columns namely Pid, Pname, Price.
Here is my code:


And this is the output:


I don't know why istead of showing the data from the table it is showing the hashcode?
Please help.>
 
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
Well you are not using parameterized types but lets assume your array list is an ArrayList<Product>. You need to override toString on your Product object. What you are seeing is the default implementation of toString() on the Object class. See the java doc

http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html#toString%28%29

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

getClass().getName() + '@' + Integer.toHexString(hashCode())



This is not really an ORM issue so I am going to move this to the beginning java forum where you can get further assistance with this if you need it.

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Basically you have got a List<Products> , then you loop around this and take out individual Products and you are printing the final Object. By default, the object's toString() method is Overridden to print the hashcode only. If you are expecting to print out the data when you print the object, then you need to Override the toString() method for the Products class and put your logic for the output.


This should work for you.

Cheers.
Vishal
 
reply
    Bookmark Topic Watch Topic
  • New Topic