• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

get whole table from database

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello i m using jpa and struts2 and i am tring to get the two or more columns of database but it gives me this :-

[[Ljava.lang.Object;@77c909, [Ljava.lang.Object;@2f7965, [Ljava.lang.Object;@cad
f36, [Ljava.lang.Object;@1048900, [Ljava.lang.Object;@be7617, [Ljava.lang.Object
;@3ae26f, [Ljava.lang.Object;@1e82106, [Ljava.lang.Object;@d034c5]


my code is:-


please help me
thanks in advance
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At what point in the code are you getting this error? You need to supply more information. That's probably why you did not get any responses yet.
 
Rancher
Posts: 43045
77
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not an error message, it's just that the object referenced by "myList" apparently does not have a terribly useful "toString" method defined. You'll have to print out each element of the list individually; since each element is apparently an array (probably of the two attributes you request), you'll need to take that into account as well.
 
Saloon Keeper
Posts: 26534
187
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a rule, I don't recommend putting the ORM code directly in the web interface (Struts service) code. It's usually much cleaner to keep the persistency code isolated from the UI and business code. Besides, that code example can leak resources. One of the reasons why I prefer Spring for my persistency.

However, the real problem here is that you're not doing the query the way you think you are.

Standard approach would be like this:


Which would result in a list of all the user details.

When you only want selected columns, your code would work, subject to the observations I just made, but what the method is actually returning is a collection of Array objects, where each element of the collection is a 2-element Array of type Object, and the elements are a[0] = firstname, and a[1] = lastname. It's an Array of Object, because you can retrieve non-String columns this way as well, and Object is the lowest-common-denominator class.

There's a name for this kind of query in JPA, although I'd have to go back and look it up. It's not actually as useful or as as it looks, however, unless resources are tight. And the fact that the returned data is not strongly typed can lead to problems detectable only at runtime.
 
Ranch Hand
Posts: 59
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:It's not an error message, it's just that the object referenced by "myList" apparently does not have a terribly useful "toString" method defined. You'll have to print out each element of the list individually; since each element is apparently an array (probably of the two attributes you request), you'll need to take that into account as well.



I agree with this. It was not an error. Here it is returning the NestedList(ie., List containing the List objects. ) SO try to cast each object with an List and display them .

List<List> mylist = query.getResultList();

for(List mylist2 : mylist){
System.out.println("the values are "+mylist2.get(0)+" - "+mylist2.get(1));

}
System.out.println(mylist);
entr.commit();



Hope your problem is cleared???
 
reply
    Bookmark Topic Watch Topic
  • New Topic