-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Quering two columns from a table
PostPosted: Thu May 22, 2008 5:14 pm 
Newbie

Joined: Thu May 22, 2008 4:56 pm
Posts: 2
Hello,
I am new to Hibernate. I am query two String value columns from one table,

Like
List<String[][]> t = session.list();

But when I loop the list to assign the values to a class members

for(String[][] p : t){
String t = p[0][0]
String s = p[0][0]
}

I keep getting a classCastException error message, I was wondering if anyone could help me how to get around with problem.
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 22, 2008 6:15 pm 
Newbie

Joined: Mon May 19, 2008 5:25 am
Posts: 5
What are the types of the 2 columns in your table?
I don't know what exactly you want to do, but in case of String java type, I think you are looking for simple thing like this:

List<String> t = session.list();

for(String s : t) {

}

if you need more help, post more information!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 22, 2008 6:43 pm 
Newbie

Joined: Thu May 22, 2008 4:56 pm
Posts: 2
The two columns are String values.
This is what I am doing after I do session.createQuery()

List<String[][]> p = query.list();

for(String[][] r = : p){
String s = r[0][0];
Stirng t = r[0][1];
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 23, 2008 2:15 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
sim133 wrote:
The two columns are String values.
This is what I am doing after I do session.createQuery()

List<String[][]> p = query.list();

for(String[][] r = : p){
String s = r[0][0];
Stirng t = r[0][1];
}


Well, you have to be aware of that what the query returns is a list of Object[], not a list of String[]. You have to make Strings out of the Objects yourself - not by casting but by calling toString() on object[i].

Carlo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 1:15 am 
Newbie

Joined: Wed Jun 11, 2008 7:51 am
Posts: 8
Why don't you create an objet to retreive the data as in?
Select new MyObject(myString, myString)... as shown in http://www.hibernate.org/hib_docs/v3/re ... hql-select


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.