• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in retrieving data with HQL

 
Sujoy Mukherjee
Ranch Hand
Posts: 51
Netbeans IDE Oracle Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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.>
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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.

 
Vishal Shaw
Ranch Hand
Posts: 179
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic