wood burning stoves*
The moose likes Beginning Java and the fly likes problem in retrieving data with HQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem in retrieving data with HQL" Watch "problem in retrieving data with HQL" New topic
Author

problem in retrieving data with HQL

Sujoy Mukherjee
Ranch Hand

Joined: Dec 31, 2005
Posts: 46

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

Joined: Mar 07, 2010
Posts: 1632
    
    7

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.



[How To Ask Questions][Read before you PM me]
Vishal Shaw
Ranch Hand

Joined: Aug 09, 2012
Posts: 179
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


Programming is about thinking, NOT coding
 
 
subject: problem in retrieving data with HQL
 
Similar Threads
Arrays are confusing
Struts & Hibernate Integration unable to delete values from MYSQL database
not persisting in HSQLDB
NULL POINTER EXCEPTION IN HIBERNATE
Hibernate generated query for a inheritance mapping