• 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

cant read the contents of the printed string

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Object obj[] = new Object[1];
obj= query.list().toArray();

for (Object x: obj) {
System.out.println(obj[0].toString());}
//[Ljava.lang.Object;@1fd6bea
//[Ljava.lang.Object;@1fd6bea
//[Ljava.lang.Object;@1fd6bea

hi-
i commented out the output to the console.
as you can see that doesnt help me.
up above query.list()[from hibernate] return type is List.

i looked everywhere and i cant figure out
how to stop it from sticking it in a
array element all mashed together in secret code.

i'd like to not only read it but break it apart.
i have fooled with this before and struggled.
i think it is time i wrote the answer down
and stick it in my manual.

please help!
jim
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The thing that jumps out at me is that you are declaring a variable, x, in your for declaration, but you have hard-coded the value that you are printing out:

For every element in the array, you print out the value of the first element in the array.
As for what is printed out, have a look at the java documentation:

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.


If you want to see something else from toString(), you will have to override it in whatever class you are expecting back from hibernate.
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with what Joe said and I would like to add my thoughts.

The following is your code:



The following is what I think you want to do.



In "new line 1", I only declare an array of objects. I don't instantiate the array since the array of objects reference variable, obj, is given a value in line 2.

In "new line 2", an object reference variable named, query, has a method named list() that returns an object that has a method named toArray() that instantiates an array with the same elements as query.list().

In "new line 3", you are using the for-each loop that came out with the Java Language version 5.0 and later. Here, the object reference variable will be assigned as each of the elements of the array called: obj.

In "new line 4", each value that was in the array of objects is converted to a String. The output that you are seeing is the result of the method of the class String called toString().

Like Joe answered, you need to override the method toString() for the objects that are in the query.list().\
[ January 15, 2008: Message edited by: Kaydell Leavitt ]
 
jim mcnamara
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi kaydell and joe-

thanks for your reply.
i am quite sure i can get it to work now.

it is very simple.

create a table in apache derby.
generate a pojo class related to the new table.
use my iterators to go through the table data.

part of the query was mapped to a table and its
fields and the rest of the fields were not mapped.

i cant believe i didnt realize this sooner.
i had a funny brain moment(s).

i havent used java in a 1/2 year or so i think.

thanks for encouraging and helping me.
i can say with 99% confidence i will get this now.

jim
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic